
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/printing.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:25:37 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Printing &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../_static/sympy-notailtext-favicon.ico"/>
    <link href="printing.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Term Rewriting" href="rewriting.html" />
    <link rel="prev" title="Introducing the domainmatrix of the poly module" href="polys/domainmatrix.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="rewriting.html" title="Term Rewriting"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="polys/domainmatrix.html" title="Introducing the domainmatrix of the poly module"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Printing</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="printing">
<h1>Printing<a class="headerlink" href="#printing" title="Permalink to this headline">¶</a></h1>
<p>See the <a class="reference internal" href="../tutorial/printing.html#tutorial-printing"><span class="std std-ref">Printing</span></a> section in tutorial for introduction into
printing.</p>
<p>This guide documents the printing system in SymPy and how it works
internally.</p>
<section id="module-sympy.printing.printer">
<span id="printer-class"></span><h2>Printer Class<a class="headerlink" href="#module-sympy.printing.printer" title="Permalink to this headline">¶</a></h2>
<p>Printing subsystem driver</p>
<p>SymPy’s printing system works the following way: Any expression can be
passed to a designated Printer who then is responsible to return an
adequate representation of that expression.</p>
<p><strong>The basic concept is the following:</strong></p>
<ol class="arabic simple">
<li><p>Let the object print itself if it knows how.</p></li>
<li><p>Take the best fitting method defined in the printer.</p></li>
<li><p>As fall-back use the emptyPrinter method for the printer.</p></li>
</ol>
<section id="which-method-is-responsible-for-printing">
<h3>Which Method is Responsible for Printing?<a class="headerlink" href="#which-method-is-responsible-for-printing" title="Permalink to this headline">¶</a></h3>
<p>The whole printing process is started by calling <code class="docutils literal notranslate"><span class="pre">.doprint(expr)</span></code> on the printer
which you want to use. This method looks for an appropriate method which can
print the given expression in the given style that the printer defines.
While looking for the method, it follows these steps:</p>
<ol class="arabic">
<li><p><strong>Let the object print itself if it knows how.</strong></p>
<p>The printer looks for a specific method in every object. The name of that method
depends on the specific printer and is defined under <code class="docutils literal notranslate"><span class="pre">Printer.printmethod</span></code>.
For example, StrPrinter calls <code class="docutils literal notranslate"><span class="pre">_sympystr</span></code> and LatexPrinter calls <code class="docutils literal notranslate"><span class="pre">_latex</span></code>.
Look at the documentation of the printer that you want to use.
The name of the method is specified there.</p>
<p>This was the original way of doing printing in sympy. Every class had
its own latex, mathml, str and repr methods, but it turned out that it
is hard to produce a high quality printer, if all the methods are spread
out that far. Therefore all printing code was combined into the different
printers, which works great for built-in sympy objects, but not that
good for user defined classes where it is inconvenient to patch the
printers.</p>
</li>
<li><p><strong>Take the best fitting method defined in the printer.</strong></p>
<p>The printer loops through expr classes (class + its bases), and tries
to dispatch the work to <code class="docutils literal notranslate"><span class="pre">_print_&lt;EXPR_CLASS&gt;</span></code></p>
<p>e.g., suppose we have the following class hierarchy:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>    <span class="n">Basic</span>
    <span class="o">|</span>
    <span class="n">Atom</span>
    <span class="o">|</span>
    <span class="n">Number</span>
    <span class="o">|</span>
<span class="n">Rational</span>
</pre></div>
</div>
<p>then, for <code class="docutils literal notranslate"><span class="pre">expr=Rational(...)</span></code>, the Printer will try
to call printer methods in the order as shown in the figure below:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>p._print(expr)
|
|-- p._print_Rational(expr)
|
|-- p._print_Number(expr)
|
|-- p._print_Atom(expr)
|
`-- p._print_Basic(expr)
</pre></div>
</div>
<p>if <code class="docutils literal notranslate"><span class="pre">._print_Rational</span></code> method exists in the printer, then it is called,
and the result is returned back. Otherwise, the printer tries to call
<code class="docutils literal notranslate"><span class="pre">._print_Number</span></code> and so on.</p>
</li>
<li><p><strong>As a fall-back use the emptyPrinter method for the printer.</strong></p>
<p>As fall-back <code class="docutils literal notranslate"><span class="pre">self.emptyPrinter</span></code> will be called with the expression. If
not defined in the Printer subclass this will be the same as <code class="docutils literal notranslate"><span class="pre">str(expr)</span></code>.</p>
</li>
</ol>
</section>
<section id="example-of-custom-printer">
<span id="printer-example"></span><h3>Example of Custom Printer<a class="headerlink" href="#example-of-custom-printer" title="Permalink to this headline">¶</a></h3>
<p>In the example below, we have a printer which prints the derivative of a function
in a shorter form.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="kn">from</span> <span class="nn">sympy.printing.latex</span> <span class="kn">import</span> <span class="n">LatexPrinter</span><span class="p">,</span> <span class="n">print_latex</span>
<span class="kn">from</span> <span class="nn">sympy.core.function</span> <span class="kn">import</span> <span class="n">UndefinedFunction</span><span class="p">,</span> <span class="n">Function</span>


<span class="k">class</span> <span class="nc">MyLatexPrinter</span><span class="p">(</span><span class="n">LatexPrinter</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Print derivative of a function of symbols in a shorter form.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">_print_Derivative</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">expr</span><span class="p">):</span>
        <span class="n">function</span><span class="p">,</span> <span class="o">*</span><span class="nb">vars</span> <span class="o">=</span> <span class="n">expr</span><span class="o">.</span><span class="n">args</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">function</span><span class="p">),</span> <span class="n">UndefinedFunction</span><span class="p">)</span> <span class="ow">or</span> \
           <span class="ow">not</span> <span class="nb">all</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">Symbol</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">vars</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_print_Derivative</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>

        <span class="c1"># If you want the printer to work correctly for nested</span>
        <span class="c1"># expressions then use self._print() instead of str() or latex().</span>
        <span class="c1"># See the example of nested modulo below in the custom printing</span>
        <span class="c1"># method section.</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">_{{</span><span class="si">{}</span><span class="s2">}}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_print</span><span class="p">(</span><span class="n">Symbol</span><span class="p">(</span><span class="n">function</span><span class="o">.</span><span class="n">func</span><span class="o">.</span><span class="vm">__name__</span><span class="p">)),</span>
                        <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">vars</span><span class="p">))</span>


<span class="k">def</span> <span class="nf">print_my_latex</span><span class="p">(</span><span class="n">expr</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Most of the printers define their own wrappers for print().</span>
<span class="sd">    These wrappers usually take printer settings. Our printer does not have</span>
<span class="sd">    any settings.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">MyLatexPrinter</span><span class="p">()</span><span class="o">.</span><span class="n">doprint</span><span class="p">(</span><span class="n">expr</span><span class="p">))</span>


<span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;y&quot;</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s2">&quot;f&quot;</span><span class="p">)</span>
<span class="n">expr</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span><span class="o">.</span><span class="n">diff</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="c1"># Print the expression using the normal latex printer and our custom</span>
<span class="c1"># printer.</span>
<span class="n">print_latex</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="n">print_my_latex</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
</pre></div>
</div>
<p>The output of the code above is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>\<span class="n">frac</span><span class="p">{</span>\<span class="n">partial</span><span class="o">^</span><span class="p">{</span><span class="mi">2</span><span class="p">}}{</span>\<span class="n">partial</span> <span class="n">x</span>\<span class="n">partial</span> <span class="n">y</span><span class="p">}</span>  <span class="n">f</span><span class="p">{</span>\<span class="n">left</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span> \<span class="n">right</span><span class="p">)}</span>
<span class="n">f_</span><span class="p">{</span><span class="n">xy</span><span class="p">}</span>
</pre></div>
</div>
</section>
<section id="example-of-custom-printing-method">
<span id="printer-method-example"></span><h3>Example of Custom Printing Method<a class="headerlink" href="#example-of-custom-printing-method" title="Permalink to this headline">¶</a></h3>
<p>In the example below, the latex printing of the modulo operator is modified.
This is done by overriding the method <code class="docutils literal notranslate"><span class="pre">_latex</span></code> of <code class="docutils literal notranslate"><span class="pre">Mod</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Mod</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.latex</span> <span class="kn">import</span> <span class="n">print_latex</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Always use printer._print()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ModOp</span><span class="p">(</span><span class="n">Mod</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">printer</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="n">printer</span><span class="o">.</span><span class="n">_print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">]</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="sa">r</span><span class="s2">&quot;\operatorname</span><span class="si">{Mod}</span><span class="s2">{\left( </span><span class="si">%s</span><span class="s2">,</span><span class="si">%s</span><span class="s2"> \right)}&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<p>Comparing the output of our custom operator to the builtin one:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;m&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">Mod</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">x\bmod{m}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOp</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">))</span>
<span class="go">\operatorname{Mod}{\left( x,m \right)}</span>
</pre></div>
</div>
<section id="common-mistakes">
<h4>Common mistakes<a class="headerlink" href="#common-mistakes" title="Permalink to this headline">¶</a></h4>
<p>It’s important to always use <code class="docutils literal notranslate"><span class="pre">self._print(obj)</span></code> to print subcomponents of
an expression when customizing a printer. Mistakes include:</p>
<ol class="arabic">
<li><p>Using <code class="docutils literal notranslate"><span class="pre">self.doprint(obj)</span></code> instead:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># This example does not work properly, as only the outermost call may use</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># doprint.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ModOpModeWrong</span><span class="p">(</span><span class="n">Mod</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">printer</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="n">printer</span><span class="o">.</span><span class="n">doprint</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">]</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="sa">r</span><span class="s2">&quot;\operatorname</span><span class="si">{Mod}</span><span class="s2">{\left( </span><span class="si">%s</span><span class="s2">,</span><span class="si">%s</span><span class="s2"> \right)}&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<p>This fails when the <span class="math notranslate nohighlight">\(mode\)</span> argument is passed to the printer:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOp</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;inline&#39;</span><span class="p">)</span>  <span class="c1"># ok</span>
<span class="go">$\operatorname{Mod}{\left( x,m \right)}$</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOpModeWrong</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;inline&#39;</span><span class="p">)</span>  <span class="c1"># bad</span>
<span class="go">$\operatorname{Mod}{\left( $x$,$m$ \right)}$</span>
</pre></div>
</div>
</li>
<li><p>Using <code class="docutils literal notranslate"><span class="pre">str(obj)</span></code> instead:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ModOpNestedWrong</span><span class="p">(</span><span class="n">Mod</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">printer</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">]</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="sa">r</span><span class="s2">&quot;\operatorname</span><span class="si">{Mod}</span><span class="s2">{\left( </span><span class="si">%s</span><span class="s2">,</span><span class="si">%s</span><span class="s2"> \right)}&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<p>This fails on nested objects:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Nested modulo.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOp</span><span class="p">(</span><span class="n">ModOp</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">Integer</span><span class="p">(</span><span class="mi">7</span><span class="p">)))</span>  <span class="c1"># ok</span>
<span class="go">\operatorname{Mod}{\left( \operatorname{Mod}{\left( x,m \right)},7 \right)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOpNestedWrong</span><span class="p">(</span><span class="n">ModOpNestedWrong</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">Integer</span><span class="p">(</span><span class="mi">7</span><span class="p">)))</span>  <span class="c1"># bad</span>
<span class="go">\operatorname{Mod}{\left( ModOpNestedWrong(x, m),7 \right)}</span>
</pre></div>
</div>
</li>
<li><p>Using <code class="docutils literal notranslate"><span class="pre">LatexPrinter()._print(obj)</span></code> instead.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.latex</span> <span class="kn">import</span> <span class="n">LatexPrinter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">ModOpSettingsWrong</span><span class="p">(</span><span class="n">Mod</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">printer</span><span class="p">):</span>
<span class="gp">... </span>        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="n">LatexPrinter</span><span class="p">()</span><span class="o">.</span><span class="n">_print</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">args</span><span class="p">]</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="sa">r</span><span class="s2">&quot;\operatorname</span><span class="si">{Mod}</span><span class="s2">{\left( </span><span class="si">%s</span><span class="s2">,</span><span class="si">%s</span><span class="s2"> \right)}&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span>
</pre></div>
</div>
<p>This causes all the settings to be discarded in the subobjects. As an
example, the <code class="docutils literal notranslate"><span class="pre">full_prec</span></code> setting which shows floats to full precision is
ignored:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Float</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOp</span><span class="p">(</span><span class="n">Float</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">full_prec</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>  <span class="c1"># ok</span>
<span class="go">\operatorname{Mod}{\left( 1.00000000000000 x,m \right)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_latex</span><span class="p">(</span><span class="n">ModOpSettingsWrong</span><span class="p">(</span><span class="n">Float</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">x</span><span class="p">,</span> <span class="n">m</span><span class="p">),</span> <span class="n">full_prec</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>  <span class="c1"># bad</span>
<span class="go">\operatorname{Mod}{\left( 1.0 x,m \right)}</span>
</pre></div>
</div>
</li>
</ol>
</section>
</section>
<p>The main class responsible for printing is <code class="docutils literal notranslate"><span class="pre">Printer</span></code> (see also its
<a class="reference external" href="https://github.com/sympy/sympy/blob/master/sympy/printing/printer.py">source code</a>):</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.printer.Printer">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.printer.</span></span><span class="sig-name descname"><span class="pre">Printer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/printer.py#L235-L349"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.printer.Printer" title="Permalink to this definition">¶</a></dt>
<dd><p>Generic printer</p>
<p>Its job is to provide infrastructure for implementing new printers easily.</p>
<p>If you want to define your custom Printer or your custom printing method
for your custom class then see the example above: <a class="reference internal" href="#printer-example">printer_example</a> .</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.printer.Printer.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">None</span></em><a class="headerlink" href="#sympy.printing.printer.Printer.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.printer.Printer._print">
<span class="sig-name descname"><span class="pre">_print</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/printer.py#L294-L335"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.printer.Printer._print" title="Permalink to this definition">¶</a></dt>
<dd><p>Internal dispatcher</p>
<dl class="simple">
<dt>Tries the following concepts to print an expression:</dt><dd><ol class="arabic simple">
<li><p>Let the object print itself if it knows how.</p></li>
<li><p>Take the best fitting method defined in the printer.</p></li>
<li><p>As fall-back use the emptyPrinter method for the printer.</p></li>
</ol>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.printer.Printer.doprint">
<span class="sig-name descname"><span class="pre">doprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/printer.py#L290-L292"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.printer.Printer.doprint" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns printer’s representation for expr (as a string)</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.printer.Printer.set_global_settings">
<em class="property"><span class="pre">classmethod</span> </em><span class="sig-name descname"><span class="pre">set_global_settings</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/printer.py#L276-L281"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.printer.Printer.set_global_settings" title="Permalink to this definition">¶</a></dt>
<dd><p>Set system-wide printing settings.</p>
</dd></dl>

</dd></dl>

</section>
<section id="prettyprinter-class">
<h2>PrettyPrinter Class<a class="headerlink" href="#prettyprinter-class" title="Permalink to this headline">¶</a></h2>
<p>The pretty printing subsystem is implemented in <code class="docutils literal notranslate"><span class="pre">sympy.printing.pretty.pretty</span></code>
by the <code class="docutils literal notranslate"><span class="pre">PrettyPrinter</span></code> class deriving from <code class="docutils literal notranslate"><span class="pre">Printer</span></code>. It relies on
the modules <code class="docutils literal notranslate"><span class="pre">sympy.printing.pretty.stringPict</span></code>, and
<code class="docutils literal notranslate"><span class="pre">sympy.printing.pretty.pretty_symbology</span></code> for rendering nice-looking
formulas.</p>
<p>The module <code class="docutils literal notranslate"><span class="pre">stringPict</span></code> provides a base class <code class="docutils literal notranslate"><span class="pre">stringPict</span></code> and a derived
class <code class="docutils literal notranslate"><span class="pre">prettyForm</span></code> that ease the creation and manipulation of formulas
that span across multiple lines.</p>
<p>The module <code class="docutils literal notranslate"><span class="pre">pretty_symbology</span></code> provides primitives to construct 2D shapes
(hline, vline, etc) together with a technique to use unicode automatically
when possible.</p>
<span class="target" id="module-sympy.printing.pretty"></span><span class="target" id="module-sympy.printing.pretty.pretty"></span><dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty.PrettyPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty.</span></span><span class="sig-name descname"><span class="pre">PrettyPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty.py#L29-L2816"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty.PrettyPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Printer, which converts an expression into 2D ASCII-art figure.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty.PrettyPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_pretty'</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty.PrettyPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty.pretty">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty.</span></span><span class="sig-name descname"><span class="pre">pretty</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full_prec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'auto'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_unicode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wrap_line</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">num_columns</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">use_unicode_sqrt_char</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">root_notation</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_symbol_style</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'plain'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">imaginary_unit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'i'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm_cyclic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty.py#L2819-L2835"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty.pretty" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a string containing the prettified form of expr.</p>
<p>For information on keyword arguments see pretty_print function.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty.pretty_print">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty.</span></span><span class="sig-name descname"><span class="pre">pretty_print</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty.py#L2838-L2881"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty.pretty_print" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints expr in pretty form.</p>
<p>pprint is just a shortcut for this function.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : expression</p>
<blockquote>
<div><p>The expression to print.</p>
</div></blockquote>
<p><strong>wrap_line</strong> : bool, optional (default=True)</p>
<blockquote>
<div><p>Line wrapping enabled/disabled.</p>
</div></blockquote>
<p><strong>num_columns</strong> : int or None, optional (default=None)</p>
<blockquote>
<div><p>Number of columns before line breaking (default to None which reads
the terminal width), useful when using SymPy without terminal.</p>
</div></blockquote>
<p><strong>use_unicode</strong> : bool or None, optional (default=None)</p>
<blockquote>
<div><p>Use unicode characters, such as the Greek letter pi instead of
the string pi.</p>
</div></blockquote>
<p><strong>full_prec</strong> : bool or string, optional (default=”auto”)</p>
<blockquote>
<div><p>Use full precision.</p>
</div></blockquote>
<p><strong>order</strong> : bool or string, optional (default=None)</p>
<blockquote>
<div><p>Set to ‘none’ for long expressions if slow; default is None.</p>
</div></blockquote>
<p><strong>use_unicode_sqrt_char</strong> : bool, optional (default=True)</p>
<blockquote>
<div><p>Use compact single-character square root symbol (when unambiguous).</p>
</div></blockquote>
<p><strong>root_notation</strong> : bool, optional (default=True)</p>
<blockquote>
<div><p>Set to ‘False’ for printing exponents of the form 1/n in fractional form.
By default exponent is printed in root form.</p>
</div></blockquote>
<p><strong>mat_symbol_style</strong> : string, optional (default=”plain”)</p>
<blockquote>
<div><p>Set to “bold” for printing MatrixSymbols using a bold mathematical symbol face.
By default the standard face is used.</p>
</div></blockquote>
<p><strong>imaginary_unit</strong> : string, optional (default=”i”)</p>
<blockquote>
<div><p>Letter to use for imaginary unit when use_unicode is True.
Can be “i” (default) or “j”.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
<section id="module-sympy.printing.c">
<span id="c-code-printers"></span><h2>C code printers<a class="headerlink" href="#module-sympy.printing.c" title="Permalink to this headline">¶</a></h2>
<p>This class implements C code printing, i.e. it converts Python expressions
to strings of C code (see also <code class="docutils literal notranslate"><span class="pre">C89CodePrinter</span></code>).</p>
<p>Usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing</span> <span class="kn">import</span> <span class="n">print_ccode</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">Abs</span><span class="p">,</span> <span class="n">gamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_ccode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">)</span>
<span class="go">pow(sin(x), 2) + pow(cos(x), 2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_ccode</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;result&quot;</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">)</span>
<span class="go">result = 2*x + cos(x);</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_ccode</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">)</span>
<span class="go">fabs(pow(x, 2))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_ccode</span><span class="p">(</span><span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C99&#39;</span><span class="p">)</span>
<span class="go">tgamma(pow(x, 2))</span>
</pre></div>
</div>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.c.known_functions_C89">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">known_functions_C89</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'fabs'),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'abs')],</span> <span class="pre">'acos':</span> <span class="pre">'acos',</span> <span class="pre">'asin':</span> <span class="pre">'asin',</span> <span class="pre">'atan':</span> <span class="pre">'atan',</span> <span class="pre">'atan2':</span> <span class="pre">'atan2',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceil',</span> <span class="pre">'cos':</span> <span class="pre">'cos',</span> <span class="pre">'cosh':</span> <span class="pre">'cosh',</span> <span class="pre">'exp':</span> <span class="pre">'exp',</span> <span class="pre">'floor':</span> <span class="pre">'floor',</span> <span class="pre">'log':</span> <span class="pre">'log',</span> <span class="pre">'sin':</span> <span class="pre">'sin',</span> <span class="pre">'sinh':</span> <span class="pre">'sinh',</span> <span class="pre">'tan':</span> <span class="pre">'tan',</span> <span class="pre">'tanh':</span> <span class="pre">'tanh'}</span></em><a class="headerlink" href="#sympy.printing.c.known_functions_C89" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.c.known_functions_C99">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">known_functions_C99</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'fabs'),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'abs')],</span> <span class="pre">'Cbrt':</span> <span class="pre">'cbrt',</span> <span class="pre">'Max':</span> <span class="pre">'fmax',</span> <span class="pre">'Min':</span> <span class="pre">'fmin',</span> <span class="pre">'acos':</span> <span class="pre">'acos',</span> <span class="pre">'acosh':</span> <span class="pre">'acosh',</span> <span class="pre">'asin':</span> <span class="pre">'asin',</span> <span class="pre">'asinh':</span> <span class="pre">'asinh',</span> <span class="pre">'atan':</span> <span class="pre">'atan',</span> <span class="pre">'atan2':</span> <span class="pre">'atan2',</span> <span class="pre">'atanh':</span> <span class="pre">'atanh',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceil',</span> <span class="pre">'cos':</span> <span class="pre">'cos',</span> <span class="pre">'cosh':</span> <span class="pre">'cosh',</span> <span class="pre">'erf':</span> <span class="pre">'erf',</span> <span class="pre">'erfc':</span> <span class="pre">'erfc',</span> <span class="pre">'exp':</span> <span class="pre">'exp',</span> <span class="pre">'exp2':</span> <span class="pre">'exp2',</span> <span class="pre">'expm1':</span> <span class="pre">'expm1',</span> <span class="pre">'floor':</span> <span class="pre">'floor',</span> <span class="pre">'fma':</span> <span class="pre">'fma',</span> <span class="pre">'gamma':</span> <span class="pre">'tgamma',</span> <span class="pre">'hypot':</span> <span class="pre">'hypot',</span> <span class="pre">'log':</span> <span class="pre">'log',</span> <span class="pre">'log10':</span> <span class="pre">'log10',</span> <span class="pre">'log1p':</span> <span class="pre">'log1p',</span> <span class="pre">'log2':</span> <span class="pre">'log2',</span> <span class="pre">'loggamma':</span> <span class="pre">'lgamma',</span> <span class="pre">'sin':</span> <span class="pre">'sin',</span> <span class="pre">'sinh':</span> <span class="pre">'sinh',</span> <span class="pre">'tan':</span> <span class="pre">'tan',</span> <span class="pre">'tanh':</span> <span class="pre">'tanh'}</span></em><a class="headerlink" href="#sympy.printing.c.known_functions_C99" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.c.C89CodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">C89CodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/c.py#L144-L628"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.c.C89CodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert python expressions to strings of c code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.c.C89CodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_ccode'</span></em><a class="headerlink" href="#sympy.printing.c.C89CodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.c.C89CodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/c.py#L445-L470"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.c.C89CodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.c.C99CodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">C99CodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/c.py#L630-L722"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.c.C99CodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.c.C99CodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_ccode'</span></em><a class="headerlink" href="#sympy.printing.c.C99CodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.c.ccode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">ccode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">standard</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'c99'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L546-L677"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.c.ccode" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of c code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned. Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type. This is helpful in case of
line-wrapping, or for expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>standard</strong> : str, optional</p>
<blockquote>
<div><p>String specifying the standard. If your compiler supports a more modern
standard you may set this to ‘c99’ to allow the printer to use more math
functions. [default=’c89’].</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi [default=17].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where the keys are string representations of either
<code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> or <code class="docutils literal notranslate"><span class="pre">UndefinedFunction</span></code> instances and the values
are their desired C string representations. Alternatively, the
dictionary value can be a list of tuples i.e. [(argument_test,
cfunction_string)] or [(argument_test, cfunction_formater)]. See below
for examples.</p>
</div></blockquote>
<p><strong>dereference</strong> : iterable, optional</p>
<blockquote>
<div><p>An iterable of symbols that should be dereferenced in the printed code
expression. These would be values passed by address to the function.
For example, if <code class="docutils literal notranslate"><span class="pre">dereference=[a]</span></code>, the resulting code would print
<code class="docutils literal notranslate"><span class="pre">(*a)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">a</span></code>.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols. If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text). [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">ccode</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">ceiling</span><span class="p">,</span> <span class="n">Abs</span><span class="p">,</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">expr</span><span class="p">)</span>
<span class="go">&#39;8*M_SQRT2*pow(tau, 7.0/2.0)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">math_macros</span><span class="o">=</span><span class="p">{})</span>
<span class="go">&#39;8*sqrt(2)*pow(tau, 7.0/2.0)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = sin(x);&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.codegen.ast</span> <span class="kn">import</span> <span class="n">real</span><span class="p">,</span> <span class="n">float80</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">type_aliases</span><span class="o">=</span><span class="p">{</span><span class="n">real</span><span class="p">:</span> <span class="n">float80</span><span class="p">})</span>
<span class="go">&#39;8*M_SQRT2l*powl(tau, 7.0L/2.0L)&#39;</span>
</pre></div>
</div>
<p>Simple custom printing can be defined for certain types by passing a
dictionary of {“type” : “function”} to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg.
Alternatively, the dictionary value can be a list of tuples i.e.
[(argument_test, cfunction_string)].</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;ceiling&quot;</span><span class="p">:</span> <span class="s2">&quot;CEIL&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;Abs&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;fabs&quot;</span><span class="p">),</span>
<span class="gp">... </span>          <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;ABS&quot;</span><span class="p">)],</span>
<span class="gp">... </span>  <span class="s2">&quot;func&quot;</span><span class="p">:</span> <span class="s2">&quot;f&quot;</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;func&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">func</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">,</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;f(fabs(x) + CEIL(x))&#39;</span>
</pre></div>
</div>
<p>or if the C-function takes a subset of the original arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">x</span> <span class="o">+</span> <span class="mi">3</span><span class="o">**</span><span class="n">x</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C99&#39;</span><span class="p">,</span> <span class="n">user_functions</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;Pow&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="gp">... </span>  <span class="p">(</span><span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="n">b</span> <span class="o">==</span> <span class="mi">2</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="s1">&#39;exp2(</span><span class="si">%s</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="n">e</span><span class="p">),</span>
<span class="gp">... </span>  <span class="p">(</span><span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="n">b</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;pow&#39;</span><span class="p">)]})</span>
<span class="go">&#39;exp2(x) + pow(3, x)&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are converted into conditionals. If an
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> variable is provided an if statement is created, otherwise
the ternary operator is used. Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a
default term, represented by <code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.
This is to prevent generating an expression that may not evaluate to
anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ccode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">tau</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">))</span>
<span class="go">if (x &gt; 0) {</span>
<span class="go">tau = x + 1;</span>
<span class="go">}</span>
<span class="go">else {</span>
<span class="go">tau = x;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">=</span><span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ccode</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">)</span>
<span class="go">&#39;Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);&#39;</span>
</pre></div>
</div>
<p>Matrices are also supported, but a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> of the same dimensions
must be provided to <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>. Note that any expression that can be
generated normally can also exist inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">)),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">ccode</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C89&#39;</span><span class="p">))</span>
<span class="go">A[0] = pow(x, 2);</span>
<span class="go">if (x &gt; 0) {</span>
<span class="go">   A[1] = x + 1;</span>
<span class="go">}</span>
<span class="go">else {</span>
<span class="go">   A[1] = x;</span>
<span class="go">}</span>
<span class="go">A[2] = sin(x);</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.c.print_ccode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.c.</span></span><span class="sig-name descname"><span class="pre">print_ccode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L679-L681"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.c.print_ccode" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints C representation of the given expression.</p>
</dd></dl>

</section>
<section id="module-sympy.printing.cxx">
<span id="id1"></span><h2>C++ code printers<a class="headerlink" href="#module-sympy.printing.cxx" title="Permalink to this headline">¶</a></h2>
<p>This module contains printers for C++ code, i.e. functions to convert
SymPy expressions to strings of C++ code.</p>
<p>Usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing</span> <span class="kn">import</span> <span class="n">cxxcode</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">Min</span><span class="p">,</span> <span class="n">gamma</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">cxxcode</span><span class="p">(</span><span class="n">Min</span><span class="p">(</span><span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="n">standard</span><span class="o">=</span><span class="s1">&#39;C++11&#39;</span><span class="p">))</span>
<span class="go">std::min(x, std::tgamma(x) - 1)</span>
</pre></div>
</div>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.cxx.CXX98CodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.cxx.</span></span><span class="sig-name descname"><span class="pre">CXX98CodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/cxx.py#L110-L112"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.cxx.CXX98CodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.cxx.CXX98CodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_cxxcode'</span></em><a class="headerlink" href="#sympy.printing.cxx.CXX98CodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.cxx.CXX11CodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.cxx.</span></span><span class="sig-name descname"><span class="pre">CXX11CodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/cxx.py#L118-L142"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.cxx.CXX11CodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.cxx.CXX11CodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_cxxcode'</span></em><a class="headerlink" href="#sympy.printing.cxx.CXX11CodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.codeprinter.cxxcode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.codeprinter.</span></span><span class="sig-name descname"><span class="pre">cxxcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">standard</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'c++11'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L810-L813"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.codeprinter.cxxcode" title="Permalink to this definition">¶</a></dt>
<dd><p>C++ equivalent of <a class="reference internal" href="#sympy.printing.c.ccode" title="sympy.printing.c.ccode"><code class="xref py py-func docutils literal notranslate"><span class="pre">ccode()</span></code></a>.</p>
</dd></dl>

</section>
<section id="module-sympy.printing.rcode">
<span id="rcodeprinter"></span><h2>RCodePrinter<a class="headerlink" href="#module-sympy.printing.rcode" title="Permalink to this headline">¶</a></h2>
<p>This class implements R code printing (i.e. it converts Python expressions
to strings of R code).</p>
<p>Usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing</span> <span class="kn">import</span> <span class="n">print_rcode</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.functions</span> <span class="kn">import</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">Abs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_rcode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">sin(x)^2 + cos(x)^2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_rcode</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;result&quot;</span><span class="p">)</span>
<span class="go">result = 2*x + cos(x);</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_rcode</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">abs(x^2)</span>
</pre></div>
</div>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.rcode.known_functions">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.rcode.</span></span><span class="sig-name descname"><span class="pre">known_functions</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">'abs',</span> <span class="pre">'Max':</span> <span class="pre">'max',</span> <span class="pre">'Min':</span> <span class="pre">'min',</span> <span class="pre">'acos':</span> <span class="pre">'acos',</span> <span class="pre">'acosh':</span> <span class="pre">'acosh',</span> <span class="pre">'asin':</span> <span class="pre">'asin',</span> <span class="pre">'asinh':</span> <span class="pre">'asinh',</span> <span class="pre">'atan':</span> <span class="pre">'atan',</span> <span class="pre">'atan2':</span> <span class="pre">'atan2',</span> <span class="pre">'atanh':</span> <span class="pre">'atanh',</span> <span class="pre">'beta':</span> <span class="pre">'beta',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceiling',</span> <span class="pre">'cos':</span> <span class="pre">'cos',</span> <span class="pre">'cosh':</span> <span class="pre">'cosh',</span> <span class="pre">'digamma':</span> <span class="pre">'digamma',</span> <span class="pre">'erf':</span> <span class="pre">'erf',</span> <span class="pre">'exp':</span> <span class="pre">'exp',</span> <span class="pre">'factorial':</span> <span class="pre">'factorial',</span> <span class="pre">'floor':</span> <span class="pre">'floor',</span> <span class="pre">'gamma':</span> <span class="pre">'gamma',</span> <span class="pre">'log':</span> <span class="pre">'log',</span> <span class="pre">'sign':</span> <span class="pre">'sign',</span> <span class="pre">'sin':</span> <span class="pre">'sin',</span> <span class="pre">'sinh':</span> <span class="pre">'sinh',</span> <span class="pre">'tan':</span> <span class="pre">'tan',</span> <span class="pre">'tanh':</span> <span class="pre">'tanh',</span> <span class="pre">'trigamma':</span> <span class="pre">'trigamma'}</span></em><a class="headerlink" href="#sympy.printing.rcode.known_functions" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.rcode.RCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.rcode.</span></span><span class="sig-name descname"><span class="pre">RCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rcode.py#L75-L303"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rcode.RCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert python expressions to strings of R code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.rcode.RCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_rcode'</span></em><a class="headerlink" href="#sympy.printing.rcode.RCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.rcode.RCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rcode.py#L277-L303"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rcode.RCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.rcode.rcode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.rcode.</span></span><span class="sig-name descname"><span class="pre">rcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rcode.py#L306-L413"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rcode.rcode" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of r code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned. Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type. This is helpful in case of
line-wrapping, or for expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi [default=15].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where the keys are string representations of either
<code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> or <code class="docutils literal notranslate"><span class="pre">UndefinedFunction</span></code> instances and the values
are their desired R string representations. Alternatively, the
dictionary value can be a list of tuples i.e. [(argument_test,
rfunction_string)] or [(argument_test, rfunction_formater)]. See below
for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols. If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text). [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">rcode</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">ceiling</span><span class="p">,</span> <span class="n">Abs</span><span class="p">,</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rcode</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8*sqrt(2)*tau^(7.0/2.0)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rcode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = sin(x);&#39;</span>
</pre></div>
</div>
<p>Simple custom printing can be defined for certain types by passing a
dictionary of {“type” : “function”} to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg.
Alternatively, the dictionary value can be a list of tuples i.e.
[(argument_test, cfunction_string)].</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;ceiling&quot;</span><span class="p">:</span> <span class="s2">&quot;CEIL&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;Abs&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;fabs&quot;</span><span class="p">),</span>
<span class="gp">... </span>          <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;ABS&quot;</span><span class="p">)],</span>
<span class="gp">... </span>  <span class="s2">&quot;func&quot;</span><span class="p">:</span> <span class="s2">&quot;f&quot;</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;func&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rcode</span><span class="p">(</span><span class="n">func</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;f(fabs(x) + CEIL(x))&#39;</span>
</pre></div>
</div>
<p>or if the R-function takes a subset of the original arguments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">rcode</span><span class="p">(</span><span class="mi">2</span><span class="o">**</span><span class="n">x</span> <span class="o">+</span> <span class="mi">3</span><span class="o">**</span><span class="n">x</span><span class="p">,</span> <span class="n">user_functions</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;Pow&#39;</span><span class="p">:</span> <span class="p">[</span>
<span class="gp">... </span>  <span class="p">(</span><span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="n">b</span> <span class="o">==</span> <span class="mi">2</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="s1">&#39;exp2(</span><span class="si">%s</span><span class="s1">)&#39;</span> <span class="o">%</span> <span class="n">e</span><span class="p">),</span>
<span class="gp">... </span>  <span class="p">(</span><span class="k">lambda</span> <span class="n">b</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span> <span class="n">b</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;pow&#39;</span><span class="p">)]})</span>
<span class="go">&#39;exp2(x) + pow(3, x)&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are converted into conditionals. If an
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> variable is provided an if statement is created, otherwise
the ternary operator is used. Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a
default term, represented by <code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.
This is to prevent generating an expression that may not evaluate to
anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rcode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">tau</span><span class="p">))</span>
<span class="go">tau = ifelse(x &gt; 0,x + 1,x);</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">=</span><span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rcode</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);&#39;</span>
</pre></div>
</div>
<p>Matrices are also supported, but a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> of the same dimensions
must be provided to <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>. Note that any expression that can be
generated normally can also exist inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">)),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rcode</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">A</span><span class="p">))</span>
<span class="go">A[0] = x^2;</span>
<span class="go">A[1] = ifelse(x &gt; 0,x + 1,x);</span>
<span class="go">A[2] = sin(x);</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.rcode.print_rcode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.rcode.</span></span><span class="sig-name descname"><span class="pre">print_rcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rcode.py#L416-L418"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rcode.print_rcode" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints R representation of the given expression.</p>
</dd></dl>

</section>
<section id="fortran-printing">
<h2>Fortran Printing<a class="headerlink" href="#fortran-printing" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">fcode</span></code> function translates a sympy expression into Fortran code. The main
purpose is to take away the burden of manually translating long mathematical
expressions. Therefore the resulting expression should also require no (or
very little) manual tweaking to make it compilable. The optional arguments
of <code class="docutils literal notranslate"><span class="pre">fcode</span></code> can be used to fine-tune the behavior of <code class="docutils literal notranslate"><span class="pre">fcode</span></code> in such a way
that manual changes in the result are no longer needed.</p>
<span class="target" id="module-sympy.printing.fortran"></span><dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.fortran.fcode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.fortran.</span></span><span class="sig-name descname"><span class="pre">fcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L683-L800"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.fortran.fcode" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of fortran code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned. Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type. This is helpful in case of
line-wrapping, or for expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>DEPRECATED. Use type_mappings instead. The precision for numbers such
as pi [default=17].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where keys are <code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> instances and values are
their string representations. Alternatively, the dictionary value can
be a list of tuples i.e. [(argument_test, cfunction_string)]. See below
for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols. If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text). [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
<p><strong>source_format</strong> : optional</p>
<blockquote>
<div><p>The source format can be either ‘fixed’ or ‘free’. [default=’fixed’]</p>
</div></blockquote>
<p><strong>standard</strong> : integer, optional</p>
<blockquote>
<div><p>The Fortran standard to be followed. This is specified as an integer.
Acceptable standards are 66, 77, 90, 95, 2003, and 2008. Default is 77.
Note that currently the only distinction internally is between
standards before 95, and those 95 and after. This may change later as
more features are added.</p>
</div></blockquote>
<p><strong>name_mangling</strong> : bool, optional</p>
<blockquote>
<div><p>If True, then the variables that would become identical in
case-insensitive Fortran are mangled by appending different number
of <code class="docutils literal notranslate"><span class="pre">_</span></code> at the end. If False, SymPy won’t interfere with naming of
variables. [default=True]</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">fcode</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">ceiling</span><span class="p">,</span> <span class="n">floor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;      8*sqrt(2.0d0)*tau**(7.0d0/2.0d0)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;      s = sin(x)&#39;</span>
</pre></div>
</div>
<p>Custom printing can be defined for certain types by passing a dictionary of
“type” : “function” to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg. Alternatively, the
dictionary value can be a list of tuples i.e. [(argument_test,
cfunction_string)].</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;ceiling&quot;</span><span class="p">:</span> <span class="s2">&quot;CEIL&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;floor&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;FLOOR1&quot;</span><span class="p">),</span>
<span class="gp">... </span>            <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;FLOOR2&quot;</span><span class="p">)]</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="n">floor</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;      CEIL(x) + FLOOR1(x)&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are converted into conditionals. If an
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> variable is provided an if statement is created, otherwise
the ternary operator is used. Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a
default term, represented by <code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.
This is to prevent generating an expression that may not evaluate to
anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">tau</span><span class="p">))</span>
<span class="go">      if (x &gt; 0) then</span>
<span class="go">         tau = x + 1</span>
<span class="go">      else</span>
<span class="go">         tau = x</span>
<span class="go">      end if</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">=</span><span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;      Dy(i) = (y(i + 1) - y(i))/(t(i + 1) - t(i))&#39;</span>
</pre></div>
</div>
<p>Matrices are also supported, but a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> of the same dimensions
must be provided to <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>. Note that any expression that can be
generated normally can also exist inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">)),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">A</span><span class="p">))</span>
<span class="go">      A(1, 1) = x**2</span>
<span class="go">         if (x &gt; 0) then</span>
<span class="go">      A(2, 1) = x + 1</span>
<span class="go">         else</span>
<span class="go">      A(2, 1) = x</span>
<span class="go">         end if</span>
<span class="go">      A(3, 1) = sin(x)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.fortran.print_fcode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.fortran.</span></span><span class="sig-name descname"><span class="pre">print_fcode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L803-L808"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.fortran.print_fcode" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints the Fortran representation of the given expression.</p>
<p>See fcode for the meaning of the optional arguments.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.fortran.FCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.fortran.</span></span><span class="sig-name descname"><span class="pre">FCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/fortran.py#L68-L775"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.fortran.FCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert sympy expressions to strings of Fortran code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.fortran.FCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_fcode'</span></em><a class="headerlink" href="#sympy.printing.fortran.FCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.fortran.FCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/fortran.py#L581-L629"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.fortran.FCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<p>Two basic examples:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;      sqrt(1 - x**2)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">((</span><span class="mi">3</span> <span class="o">+</span> <span class="mi">4</span><span class="o">*</span><span class="n">I</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">conjugate</span><span class="p">(</span><span class="n">x</span><span class="p">)))</span>
<span class="go">&#39;      (cmplx(3,4))/(1 - conjg(x))&#39;</span>
</pre></div>
</div>
<p>An example where line wrapping is required:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">sqrt</span><span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">n</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span><span class="o">.</span><span class="n">removeO</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">expr</span><span class="p">))</span>
<span class="go">    -715.0d0/65536.0d0*x**18 - 429.0d0/32768.0d0*x**16 - 33.0d0/</span>
<span class="go">    @ 2048.0d0*x**14 - 21.0d0/1024.0d0*x**12 - 7.0d0/256.0d0*x**10 -</span>
<span class="go">    @ 5.0d0/128.0d0*x**8 - 1.0d0/16.0d0*x**6 - 1.0d0/8.0d0*x**4 - 1.0d0</span>
<span class="go">    @ /2.0d0*x**2 + 1</span>
</pre></div>
</div>
<p>In case of line wrapping, it is handy to include the assignment so that lines
are wrapped properly when the assignment part is added.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;var&quot;</span><span class="p">))</span>
<span class="go">      var = -715.0d0/65536.0d0*x**18 - 429.0d0/32768.0d0*x**16 - 33.0d0/</span>
<span class="go">     @ 2048.0d0*x**14 - 21.0d0/1024.0d0*x**12 - 7.0d0/256.0d0*x**10 -</span>
<span class="go">     @ 5.0d0/128.0d0*x**8 - 1.0d0/16.0d0*x**6 - 1.0d0/8.0d0*x**4 - 1.0d0</span>
<span class="go">     @ /2.0d0*x**2 + 1</span>
</pre></div>
</div>
<p>For piecewise functions, the <code class="docutils literal notranslate"><span class="pre">assign_to</span></code> option is mandatory:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span><span class="p">,</span><span class="n">x</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">),(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span><span class="kc">True</span><span class="p">)),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;var&quot;</span><span class="p">))</span>
<span class="go">      if (x &lt; 1) then</span>
<span class="go">        var = x</span>
<span class="go">      else</span>
<span class="go">        var = x**2</span>
<span class="go">      end if</span>
</pre></div>
</div>
<p>Note that by default only top-level piecewise functions are supported due to
the lack of a conditional operator in Fortran 77. Inline conditionals can be
supported using the <code class="docutils literal notranslate"><span class="pre">merge</span></code> function introduced in Fortran 95 by setting of
the kwarg <code class="docutils literal notranslate"><span class="pre">standard=95</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span><span class="p">,</span><span class="n">x</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">),(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span><span class="kc">True</span><span class="p">)),</span> <span class="n">standard</span><span class="o">=</span><span class="mi">95</span><span class="p">))</span>
<span class="go">      merge(x, x**2, x &lt; 1)</span>
</pre></div>
</div>
<p>Loops are generated if there are Indexed objects in the expression. This
also requires use of the assign_to option.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">,</span> <span class="n">B</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="n">IndexedBase</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;m&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">m</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">B</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="go">    do i = 1, m</span>
<span class="go">        A(i) = 2*B(i)</span>
<span class="go">    end do</span>
</pre></div>
</div>
<p>Repeated indices in an expression with Indexed objects are interpreted as
summation. For instance, code for the trace of a matrix can be generated
with</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">A</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="n">i</span><span class="p">],</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">x</span><span class="p">))</span>
<span class="go">      x = 0</span>
<span class="go">      do i = 1, m</span>
<span class="go">          x = x + A(i, i)</span>
<span class="go">      end do</span>
</pre></div>
</div>
<p>By default, number symbols such as <code class="docutils literal notranslate"><span class="pre">pi</span></code> and <code class="docutils literal notranslate"><span class="pre">E</span></code> are detected and defined as
Fortran parameters. The precision of the constants can be tuned with the
precision argument. Parameter definitions are easily avoided using the <code class="docutils literal notranslate"><span class="pre">N</span></code>
function.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">pi</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">E</span><span class="p">))</span>
<span class="go">      parameter (E = 2.7182818284590452d0)</span>
<span class="go">      parameter (pi = 3.1415926535897932d0)</span>
<span class="go">      x - pi**2 - E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">pi</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">E</span><span class="p">,</span> <span class="n">precision</span><span class="o">=</span><span class="mi">25</span><span class="p">))</span>
<span class="go">      parameter (E = 2.718281828459045235360287d0)</span>
<span class="go">      parameter (pi = 3.141592653589793238462643d0)</span>
<span class="go">      x - pi**2 - E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="n">N</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">pi</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="mi">25</span><span class="p">)))</span>
<span class="go">      x - 9.869604401089358618834491d0</span>
</pre></div>
</div>
<p>When some functions are not part of the Fortran standard, it might be desirable
to introduce the names of user-defined functions in the Fortran expression.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">user_functions</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;gamma&#39;</span><span class="p">:</span> <span class="s1">&#39;mygamma&#39;</span><span class="p">}))</span>
<span class="go">      1 - mygamma(x)**2</span>
</pre></div>
</div>
<p>However, when the user_functions argument is not provided, <code class="docutils literal notranslate"><span class="pre">fcode</span></code> will
generate code which assumes that a function of the same name will be provided
by the user.  A comment will be added to inform the user of the issue:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="go">C     Not supported in Fortran:</span>
<span class="go">C     gamma</span>
<span class="go">      1 - gamma(x)**2</span>
</pre></div>
</div>
<p>The printer can be configured to omit these comments:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">fcode</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">allow_unknown_functions</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">      1 - gamma(x)**2</span>
</pre></div>
</div>
<p>By default the output is human readable code, ready for copy and paste. With the
option <code class="docutils literal notranslate"><span class="pre">human=False</span></code>, the return value is suitable for post-processing with
source code generators that write routines with multiple instructions. The
return value is a three-tuple containing: (i) a set of number symbols that must
be defined as ‘Fortran parameters’, (ii) a list functions that cannot be
translated in pure Fortran and (iii) a string of Fortran code. A few examples:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">gamma</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">human</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(set(), {gamma(x)}, &#39;      1 - gamma(x)**2&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">human</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">(set(), set(), &#39;      1 - sin(x)**2&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fcode</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">pi</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">human</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">({(pi, &#39;3.1415926535897932d0&#39;)}, set(), &#39;      x - pi**2&#39;)</span>
</pre></div>
</div>
</section>
<section id="module-sympy.printing.mathematica">
<span id="mathematica-code-printing"></span><h2>Mathematica code printing<a class="headerlink" href="#module-sympy.printing.mathematica" title="Permalink to this headline">¶</a></h2>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.mathematica.known_functions">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.mathematica.</span></span><span class="sig-name descname"><span class="pre">known_functions</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Chi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'CoshIntegral')],</span> <span class="pre">'Ci':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'CosIntegral')],</span> <span class="pre">'DiracDelta':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'DiracDelta')],</span> <span class="pre">'Ei':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ExpIntegralEi')],</span> <span class="pre">'FallingFactorial':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'FactorialPower')],</span> <span class="pre">'Heaviside':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HeavisideTheta')],</span> <span class="pre">'KroneckerDelta':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'KroneckerDelta')],</span> <span class="pre">'Max':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Max')],</span> <span class="pre">'Min':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Min')],</span> <span class="pre">'RisingFactorial':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Pochhammer')],</span> <span class="pre">'Shi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'SinhIntegral')],</span> <span class="pre">'Si':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'SinIntegral')],</span> <span class="pre">'acos':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCos')],</span> <span class="pre">'acosh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCosh')],</span> <span class="pre">'acot':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCot')],</span> <span class="pre">'acoth':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCoth')],</span> <span class="pre">'acsc':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCsc')],</span> <span class="pre">'acsch':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcCsch')],</span> <span class="pre">'airyai':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'AiryAi')],</span> <span class="pre">'airyaiprime':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'AiryAiPrime')],</span> <span class="pre">'airybi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'AiryBi')],</span> <span class="pre">'airybiprime':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'AiryBiPrime')],</span> <span class="pre">'appellf1':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'AppellF1')],</span> <span class="pre">'asec':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcSec')],</span> <span class="pre">'asech':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcSech')],</span> <span class="pre">'asin':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcSin')],</span> <span class="pre">'asinh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcSinh')],</span> <span class="pre">'assoc_laguerre':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LaguerreL')],</span> <span class="pre">'assoc_legendre':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LegendreP')],</span> <span class="pre">'atan':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcTan')],</span> <span class="pre">'atan2':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcTan')],</span> <span class="pre">'atanh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ArcTanh')],</span> <span class="pre">'besseli':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'BesselI')],</span> <span class="pre">'besselj':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'BesselJ')],</span> <span class="pre">'besselk':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'BesselK')],</span> <span class="pre">'bessely':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'BesselY')],</span> <span class="pre">'beta':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Beta')],</span> <span class="pre">'catalan':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'CatalanNumber')],</span> <span class="pre">'chebyshevt':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ChebyshevT')],</span> <span class="pre">'chebyshevu':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ChebyshevU')],</span> <span class="pre">'conjugate':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Conjugate')],</span> <span class="pre">'cos':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Cos')],</span> <span class="pre">'cosh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Cosh')],</span> <span class="pre">'cot':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Cot')],</span> <span class="pre">'coth':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Coth')],</span> <span class="pre">'csc':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Csc')],</span> <span class="pre">'csch':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Csch')],</span> <span class="pre">'elliptic_e':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'EllipticE')],</span> <span class="pre">'elliptic_f':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'EllipticE')],</span> <span class="pre">'elliptic_k':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'EllipticK')],</span> <span class="pre">'elliptic_pi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'EllipticPi')],</span> <span class="pre">'erf':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Erf')],</span> <span class="pre">'erf2':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Erf')],</span> <span class="pre">'erf2inv':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'InverseErf')],</span> <span class="pre">'erfc':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Erfc')],</span> <span class="pre">'erfcinv':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'InverseErfc')],</span> <span class="pre">'erfi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Erfi')],</span> <span class="pre">'erfinv':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'InverseErf')],</span> <span class="pre">'exp':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Exp')],</span> <span class="pre">'expint':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'ExpIntegralE')],</span> <span class="pre">'factorial':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Factorial')],</span> <span class="pre">'factorial2':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Factorial2')],</span> <span class="pre">'fresnelc':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'FresnelC')],</span> <span class="pre">'fresnels':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'FresnelS')],</span> <span class="pre">'gamma':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Gamma')],</span> <span class="pre">'gcd':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'GCD')],</span> <span class="pre">'gegenbauer':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'GegenbauerC')],</span> <span class="pre">'hankel1':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HankelH1')],</span> <span class="pre">'hankel2':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HankelH2')],</span> <span class="pre">'harmonic':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HarmonicNumber')],</span> <span class="pre">'hermite':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HermiteH')],</span> <span class="pre">'hyper':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'HypergeometricPFQ')],</span> <span class="pre">'jacobi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'JacobiP')],</span> <span class="pre">'jn':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'SphericalBesselJ')],</span> <span class="pre">'laguerre':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LaguerreL')],</span> <span class="pre">'lcm':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LCM')],</span> <span class="pre">'legendre':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LegendreP')],</span> <span class="pre">'lerchphi':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LerchPhi')],</span> <span class="pre">'li':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LogIntegral')],</span> <span class="pre">'log':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Log')],</span> <span class="pre">'loggamma':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'LogGamma')],</span> <span class="pre">'mathieuc':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'MathieuC')],</span> <span class="pre">'mathieucprime':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'MathieuCPrime')],</span> <span class="pre">'mathieus':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'MathieuS')],</span> <span class="pre">'mathieusprime':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'MathieuSPrime')],</span> <span class="pre">'meijerg':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'MeijerG')],</span> <span class="pre">'polygamma':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'PolyGamma')],</span> <span class="pre">'polylog':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'PolyLog')],</span> <span class="pre">'sec':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Sec')],</span> <span class="pre">'sech':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Sech')],</span> <span class="pre">'sin':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Sin')],</span> <span class="pre">'sinh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Sinh')],</span> <span class="pre">'stieltjes':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'StieltjesGamma')],</span> <span class="pre">'subfactorial':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Subfactorial')],</span> <span class="pre">'tan':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Tan')],</span> <span class="pre">'tanh':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Tanh')],</span> <span class="pre">'uppergamma':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Gamma')],</span> <span class="pre">'yn':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'SphericalBesselY')],</span> <span class="pre">'zeta':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'Zeta')]}</span></em><a class="headerlink" href="#sympy.printing.mathematica.known_functions" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.mathematica.MCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.mathematica.</span></span><span class="sig-name descname"><span class="pre">MCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathematica.py#L116-L333"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathematica.MCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert python expressions to
strings of the Wolfram’s Mathematica code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.mathematica.MCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_mcode'</span></em><a class="headerlink" href="#sympy.printing.mathematica.MCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.mathematica.mathematica_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.mathematica.</span></span><span class="sig-name descname"><span class="pre">mathematica_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathematica.py#L336-L347"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathematica.mathematica_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of the Wolfram Mathematica code</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">mathematica_code</span> <span class="k">as</span> <span class="n">mcode</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mcode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">removeO</span><span class="p">())</span>
<span class="go">&#39;(1/120)*x^5 - 1/6*x^3 + x&#39;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.maple">
<span id="maple-code-printing"></span><h2>Maple code printing<a class="headerlink" href="#module-sympy.printing.maple" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.maple.MapleCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.maple.</span></span><span class="sig-name descname"><span class="pre">MapleCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/maple.py#L72-L247"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.maple.MapleCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Printer which converts a sympy expression into a maple code.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.maple.MapleCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_maple'</span></em><a class="headerlink" href="#sympy.printing.maple.MapleCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.maple.maple_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.maple.</span></span><span class="sig-name descname"><span class="pre">maple_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/maple.py#L250-L286"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.maple.maple_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts <code class="docutils literal notranslate"><span class="pre">expr</span></code> to a string of Maple code.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned.  Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type.  This can be helpful for
expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi  [default=16].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where keys are <code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> instances and values are
their string representations.  Alternatively, the dictionary value can
be a list of tuples i.e. [(argument_test, cfunction_string)].  See
below for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols.  If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text).  [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
<p><strong>inline: bool, optional</strong></p>
<blockquote>
<div><p>If True, we try to create single-statement code instead of multiple
statements.  [default=True].</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.maple.print_maple_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.maple.</span></span><span class="sig-name descname"><span class="pre">print_maple_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/maple.py#L289-L303"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.maple.print_maple_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints the Maple representation of the given expression.</p>
<p>See <a class="reference internal" href="#sympy.printing.maple.maple_code" title="sympy.printing.maple.maple_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">maple_code()</span></code></a> for the meaning of the optional arguments.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.maple</span> <span class="kn">import</span> <span class="n">print_maple_code</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x y&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_maple_code</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">y</span><span class="p">)</span>
<span class="go">y := x</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.jscode">
<span id="javascript-code-printing"></span><h2>Javascript Code printing<a class="headerlink" href="#module-sympy.printing.jscode" title="Permalink to this headline">¶</a></h2>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.jscode.known_functions">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.jscode.</span></span><span class="sig-name descname"><span class="pre">known_functions</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">'Math.abs',</span> <span class="pre">'Max':</span> <span class="pre">'Math.max',</span> <span class="pre">'Min':</span> <span class="pre">'Math.min',</span> <span class="pre">'acos':</span> <span class="pre">'Math.acos',</span> <span class="pre">'acosh':</span> <span class="pre">'Math.acosh',</span> <span class="pre">'asin':</span> <span class="pre">'Math.asin',</span> <span class="pre">'asinh':</span> <span class="pre">'Math.asinh',</span> <span class="pre">'atan':</span> <span class="pre">'Math.atan',</span> <span class="pre">'atan2':</span> <span class="pre">'Math.atan2',</span> <span class="pre">'atanh':</span> <span class="pre">'Math.atanh',</span> <span class="pre">'ceiling':</span> <span class="pre">'Math.ceil',</span> <span class="pre">'cos':</span> <span class="pre">'Math.cos',</span> <span class="pre">'cosh':</span> <span class="pre">'Math.cosh',</span> <span class="pre">'exp':</span> <span class="pre">'Math.exp',</span> <span class="pre">'floor':</span> <span class="pre">'Math.floor',</span> <span class="pre">'log':</span> <span class="pre">'Math.log',</span> <span class="pre">'sign':</span> <span class="pre">'Math.sign',</span> <span class="pre">'sin':</span> <span class="pre">'Math.sin',</span> <span class="pre">'sinh':</span> <span class="pre">'Math.sinh',</span> <span class="pre">'tan':</span> <span class="pre">'Math.tan',</span> <span class="pre">'tanh':</span> <span class="pre">'Math.tanh'}</span></em><a class="headerlink" href="#sympy.printing.jscode.known_functions" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.jscode.JavascriptCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.jscode.</span></span><span class="sig-name descname"><span class="pre">JavascriptCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/jscode.py#L44-L209"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.jscode.JavascriptCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>“A Printer to convert python expressions to strings of javascript code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.jscode.JavascriptCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_javascript'</span></em><a class="headerlink" href="#sympy.printing.jscode.JavascriptCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.jscode.JavascriptCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/jscode.py#L183-L209"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.jscode.JavascriptCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.jscode.jscode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.jscode.</span></span><span class="sig-name descname"><span class="pre">jscode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/jscode.py#L212-L317"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.jscode.jscode" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of javascript code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned. Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type. This is helpful in case of
line-wrapping, or for expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi [default=15].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where keys are <code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> instances and values are
their string representations. Alternatively, the dictionary value can
be a list of tuples i.e. [(argument_test, js_function_string)]. See
below for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols. If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text). [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">jscode</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">ceiling</span><span class="p">,</span> <span class="n">Abs</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jscode</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8*Math.sqrt(2)*Math.pow(tau, 7/2)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jscode</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = Math.sin(x);&#39;</span>
</pre></div>
</div>
<p>Custom printing can be defined for certain types by passing a dictionary of
“type” : “function” to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg. Alternatively, the
dictionary value can be a list of tuples i.e. [(argument_test,
js_function_string)].</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;ceiling&quot;</span><span class="p">:</span> <span class="s2">&quot;CEIL&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;Abs&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;fabs&quot;</span><span class="p">),</span>
<span class="gp">... </span>          <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;ABS&quot;</span><span class="p">)]</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jscode</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;fabs(x) + CEIL(x)&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are converted into conditionals. If an
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> variable is provided an if statement is created, otherwise
the ternary operator is used. Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a
default term, represented by <code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.
This is to prevent generating an expression that may not evaluate to
anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">jscode</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">tau</span><span class="p">))</span>
<span class="go">if (x &gt; 0) {</span>
<span class="go">   tau = x + 1;</span>
<span class="go">}</span>
<span class="go">else {</span>
<span class="go">   tau = x;</span>
<span class="go">}</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">=</span><span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">jscode</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);&#39;</span>
</pre></div>
</div>
<p>Matrices are also supported, but a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> of the same dimensions
must be provided to <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>. Note that any expression that can be
generated normally can also exist inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">)),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">jscode</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">A</span><span class="p">))</span>
<span class="go">A[0] = Math.pow(x, 2);</span>
<span class="go">if (x &gt; 0) {</span>
<span class="go">   A[1] = x + 1;</span>
<span class="go">}</span>
<span class="go">else {</span>
<span class="go">   A[1] = x;</span>
<span class="go">}</span>
<span class="go">A[2] = Math.sin(x);</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.julia">
<span id="julia-code-printing"></span><h2>Julia code printing<a class="headerlink" href="#module-sympy.printing.julia" title="Permalink to this headline">¶</a></h2>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.julia.known_fcns_src1">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.julia.</span></span><span class="sig-name descname"><span class="pre">known_fcns_src1</span></span><em class="property"> <span class="pre">=</span> <span class="pre">['sin',</span> <span class="pre">'cos',</span> <span class="pre">'tan',</span> <span class="pre">'cot',</span> <span class="pre">'sec',</span> <span class="pre">'csc',</span> <span class="pre">'asin',</span> <span class="pre">'acos',</span> <span class="pre">'atan',</span> <span class="pre">'acot',</span> <span class="pre">'asec',</span> <span class="pre">'acsc',</span> <span class="pre">'sinh',</span> <span class="pre">'cosh',</span> <span class="pre">'tanh',</span> <span class="pre">'coth',</span> <span class="pre">'sech',</span> <span class="pre">'csch',</span> <span class="pre">'asinh',</span> <span class="pre">'acosh',</span> <span class="pre">'atanh',</span> <span class="pre">'acoth',</span> <span class="pre">'asech',</span> <span class="pre">'acsch',</span> <span class="pre">'sinc',</span> <span class="pre">'atan2',</span> <span class="pre">'sign',</span> <span class="pre">'floor',</span> <span class="pre">'log',</span> <span class="pre">'exp',</span> <span class="pre">'cbrt',</span> <span class="pre">'sqrt',</span> <span class="pre">'erf',</span> <span class="pre">'erfc',</span> <span class="pre">'erfi',</span> <span class="pre">'factorial',</span> <span class="pre">'gamma',</span> <span class="pre">'digamma',</span> <span class="pre">'trigamma',</span> <span class="pre">'polygamma',</span> <span class="pre">'beta',</span> <span class="pre">'airyai',</span> <span class="pre">'airyaiprime',</span> <span class="pre">'airybi',</span> <span class="pre">'airybiprime',</span> <span class="pre">'besselj',</span> <span class="pre">'bessely',</span> <span class="pre">'besseli',</span> <span class="pre">'besselk',</span> <span class="pre">'erfinv',</span> <span class="pre">'erfcinv']</span></em><a class="headerlink" href="#sympy.printing.julia.known_fcns_src1" title="Permalink to this definition">¶</a></dt>
<dd><p>Built-in mutable sequence.</p>
<p>If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.julia.known_fcns_src2">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.julia.</span></span><span class="sig-name descname"><span class="pre">known_fcns_src2</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">'abs',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceil',</span> <span class="pre">'conjugate':</span> <span class="pre">'conj',</span> <span class="pre">'hankel1':</span> <span class="pre">'hankelh1',</span> <span class="pre">'hankel2':</span> <span class="pre">'hankelh2',</span> <span class="pre">'im':</span> <span class="pre">'imag',</span> <span class="pre">'re':</span> <span class="pre">'real'}</span></em><a class="headerlink" href="#sympy.printing.julia.known_fcns_src2" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.julia.JuliaCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.julia.</span></span><span class="sig-name descname"><span class="pre">JuliaCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/julia.py#L46-L489"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.julia.JuliaCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert expressions to strings of Julia code.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.julia.JuliaCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_julia'</span></em><a class="headerlink" href="#sympy.printing.julia.JuliaCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.julia.JuliaCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/julia.py#L460-L489"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.julia.JuliaCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.julia.julia_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.julia.</span></span><span class="sig-name descname"><span class="pre">julia_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/julia.py#L492-L626"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.julia.julia_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts <span class="math notranslate nohighlight">\(expr\)</span> to a string of Julia code.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned.  Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type.  This can be helpful for
expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi  [default=16].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where keys are <code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> instances and values are
their string representations.  Alternatively, the dictionary value can
be a list of tuples i.e. [(argument_test, cfunction_string)].  See
below for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols.  If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text).  [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
<p><strong>inline: bool, optional</strong></p>
<blockquote>
<div><p>If True, we try to create single-statement code instead of multiple
statements.  [default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">julia_code</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">removeO</span><span class="p">())</span>
<span class="go">&#39;x.^5/120 - x.^3/6 + x&#39;</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">ceiling</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, y, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8*sqrt(2)*tau.^(7/2)&#39;</span>
</pre></div>
</div>
<p>Note that element-wise (Hadamard) operations are used by default between
symbols.  This is because its possible in Julia to write “vectorized”
code.  It is harmless if the values are scalars.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">pi</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = sin(pi*x.*y)&#39;</span>
</pre></div>
</div>
<p>If you need a matrix product “*” or matrix power “^”, you can specify the
symbol as a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">A</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&#39;(3*pi)*A^3&#39;</span>
</pre></div>
</div>
<p>This class uses several rules to decide which symbol to use a product.
Pure numbers use “*”, Symbols use “.*” and MatrixSymbols use “*”.
A HadamardProduct can be used to specify componentwise multiplication “.*”
of two MatrixSymbols.  There is currently there is no easy way to specify
scalar symbols, so sometimes the code might have some minor cosmetic
issues.  For example, suppose x and y are scalars and A is a Matrix, then
while a human programmer might write “(x^2*y)*A^3”, we generate:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">A</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&#39;(x.^2.*y)*A^3&#39;</span>
</pre></div>
</div>
<p>Matrices are supported using Julia inline notation.  When using
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> with matrices, the name can be specified either as a string
or as a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>.  The dimensions must align in the latter case.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="go">&#39;A = [x.^2 sin(x) ceil(x)]&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are implemented with logical masking by default.
Alternatively, you can pass “inline=False” to use if-else conditionals.
Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a default term, represented by
<code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.  This is to prevent
generating an expression that may not evaluate to anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pw</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">pw</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">tau</span><span class="p">)</span>
<span class="go">&#39;tau = ((x &gt; 0) ? (x + 1) : (x))&#39;</span>
</pre></div>
</div>
<p>Note that any expression that can be generated normally can also exist
inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">pw</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="go">&#39;A = [x.^2 ((x &gt; 0) ? (x + 1) : (x)) sin(x)]&#39;</span>
</pre></div>
</div>
<p>Custom printing can be defined for certain types by passing a dictionary of
“type” : “function” to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg.  Alternatively, the
dictionary value can be a list of tuples i.e., [(argument_test,
cfunction_string)].  This can be used to call a custom Julia function.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;f&quot;</span><span class="p">:</span> <span class="s2">&quot;existing_julia_fcn&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;g&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Matrix</span><span class="p">,</span> <span class="s2">&quot;my_mat_fcn&quot;</span><span class="p">),</span>
<span class="gp">... </span>        <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Matrix</span><span class="p">,</span> <span class="s2">&quot;my_fcn&quot;</span><span class="p">)]</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">g</span><span class="p">(</span><span class="n">mat</span><span class="p">),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;existing_julia_fcn(x) + my_fcn(x) + my_mat_fcn([1 x])&#39;</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">julia_code</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;Dy[i] = (y[i + 1] - y[i])./(t[i + 1] - t[i])&#39;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.octave">
<span id="octave-and-matlab-code-printing"></span><h2>Octave (and Matlab) Code printing<a class="headerlink" href="#module-sympy.printing.octave" title="Permalink to this headline">¶</a></h2>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.octave.known_fcns_src1">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.octave.</span></span><span class="sig-name descname"><span class="pre">known_fcns_src1</span></span><em class="property"> <span class="pre">=</span> <span class="pre">['sin',</span> <span class="pre">'cos',</span> <span class="pre">'tan',</span> <span class="pre">'cot',</span> <span class="pre">'sec',</span> <span class="pre">'csc',</span> <span class="pre">'asin',</span> <span class="pre">'acos',</span> <span class="pre">'acot',</span> <span class="pre">'atan',</span> <span class="pre">'atan2',</span> <span class="pre">'asec',</span> <span class="pre">'acsc',</span> <span class="pre">'sinh',</span> <span class="pre">'cosh',</span> <span class="pre">'tanh',</span> <span class="pre">'coth',</span> <span class="pre">'csch',</span> <span class="pre">'sech',</span> <span class="pre">'asinh',</span> <span class="pre">'acosh',</span> <span class="pre">'atanh',</span> <span class="pre">'acoth',</span> <span class="pre">'asech',</span> <span class="pre">'acsch',</span> <span class="pre">'erfc',</span> <span class="pre">'erfi',</span> <span class="pre">'erf',</span> <span class="pre">'erfinv',</span> <span class="pre">'erfcinv',</span> <span class="pre">'besseli',</span> <span class="pre">'besselj',</span> <span class="pre">'besselk',</span> <span class="pre">'bessely',</span> <span class="pre">'bernoulli',</span> <span class="pre">'beta',</span> <span class="pre">'euler',</span> <span class="pre">'exp',</span> <span class="pre">'factorial',</span> <span class="pre">'floor',</span> <span class="pre">'fresnelc',</span> <span class="pre">'fresnels',</span> <span class="pre">'gamma',</span> <span class="pre">'harmonic',</span> <span class="pre">'log',</span> <span class="pre">'polylog',</span> <span class="pre">'sign',</span> <span class="pre">'zeta',</span> <span class="pre">'legendre']</span></em><a class="headerlink" href="#sympy.printing.octave.known_fcns_src1" title="Permalink to this definition">¶</a></dt>
<dd><p>Built-in mutable sequence.</p>
<p>If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.octave.known_fcns_src2">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.octave.</span></span><span class="sig-name descname"><span class="pre">known_fcns_src2</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">'abs',</span> <span class="pre">'Chi':</span> <span class="pre">'coshint',</span> <span class="pre">'Ci':</span> <span class="pre">'cosint',</span> <span class="pre">'DiracDelta':</span> <span class="pre">'dirac',</span> <span class="pre">'Heaviside':</span> <span class="pre">'heaviside',</span> <span class="pre">'LambertW':</span> <span class="pre">'lambertw',</span> <span class="pre">'Max':</span> <span class="pre">'max',</span> <span class="pre">'Min':</span> <span class="pre">'min',</span> <span class="pre">'Mod':</span> <span class="pre">'mod',</span> <span class="pre">'RisingFactorial':</span> <span class="pre">'pochhammer',</span> <span class="pre">'Shi':</span> <span class="pre">'sinhint',</span> <span class="pre">'Si':</span> <span class="pre">'sinint',</span> <span class="pre">'arg':</span> <span class="pre">'angle',</span> <span class="pre">'binomial':</span> <span class="pre">'bincoeff',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceil',</span> <span class="pre">'chebyshevt':</span> <span class="pre">'chebyshevT',</span> <span class="pre">'chebyshevu':</span> <span class="pre">'chebyshevU',</span> <span class="pre">'conjugate':</span> <span class="pre">'conj',</span> <span class="pre">'im':</span> <span class="pre">'imag',</span> <span class="pre">'laguerre':</span> <span class="pre">'laguerreL',</span> <span class="pre">'li':</span> <span class="pre">'logint',</span> <span class="pre">'loggamma':</span> <span class="pre">'gammaln',</span> <span class="pre">'polygamma':</span> <span class="pre">'psi',</span> <span class="pre">'re':</span> <span class="pre">'real'}</span></em><a class="headerlink" href="#sympy.printing.octave.known_fcns_src2" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.octave.OctaveCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.octave.</span></span><span class="sig-name descname"><span class="pre">OctaveCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/octave.py#L63-L569"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.octave.OctaveCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert expressions to strings of Octave/Matlab code.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.octave.OctaveCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_octave'</span></em><a class="headerlink" href="#sympy.printing.octave.OctaveCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.octave.OctaveCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/octave.py#L540-L569"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.octave.OctaveCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.octave.octave_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.octave.</span></span><span class="sig-name descname"><span class="pre">octave_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/octave.py#L572-L708"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.octave.octave_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts <span class="math notranslate nohighlight">\(expr\)</span> to a string of Octave (or Matlab) code.</p>
<p>The string uses a subset of the Octave language for Matlab compatibility.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned.  Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type.  This can be helpful for
expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi  [default=16].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where keys are <code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> instances and values are
their string representations.  Alternatively, the dictionary value can
be a list of tuples i.e. [(argument_test, cfunction_string)].  See
below for examples.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols.  If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text).  [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
<p><strong>inline: bool, optional</strong></p>
<blockquote>
<div><p>If True, we try to create single-statement code instead of multiple
statements.  [default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">octave_code</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">series</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">.</span><span class="n">removeO</span><span class="p">())</span>
<span class="go">&#39;x.^5/120 - x.^3/6 + x&#39;</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">ceiling</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, y, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8*sqrt(2)*tau.^(7/2)&#39;</span>
</pre></div>
</div>
<p>Note that element-wise (Hadamard) operations are used by default between
symbols.  This is because its very common in Octave to write “vectorized”
code.  It is harmless if the values are scalars.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">pi</span><span class="o">*</span><span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = sin(pi*x.*y);&#39;</span>
</pre></div>
</div>
<p>If you need a matrix product “*” or matrix power “^”, you can specify the
symbol as a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">n</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;n&#39;</span><span class="p">,</span> <span class="n">integer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">positive</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">A</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&#39;(3*pi)*A^3&#39;</span>
</pre></div>
</div>
<p>This class uses several rules to decide which symbol to use a product.
Pure numbers use “*”, Symbols use “.*” and MatrixSymbols use “*”.
A HadamardProduct can be used to specify componentwise multiplication “.*”
of two MatrixSymbols.  There is currently there is no easy way to specify
scalar symbols, so sometimes the code might have some minor cosmetic
issues.  For example, suppose x and y are scalars and A is a Matrix, then
while a human programmer might write “(x^2*y)*A^3”, we generate:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">*</span><span class="n">y</span><span class="o">*</span><span class="n">A</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">&#39;(x.^2.*y)*A^3&#39;</span>
</pre></div>
</div>
<p>Matrices are supported using Octave inline notation.  When using
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> with matrices, the name can be specified either as a string
or as a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>.  The dimensions must align in the latter case.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="go">&#39;A = [x.^2 sin(x) ceil(x)];&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are implemented with logical masking by default.
Alternatively, you can pass “inline=False” to use if-else conditionals.
Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a default term, represented by
<code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.  This is to prevent
generating an expression that may not evaluate to anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pw</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">pw</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">tau</span><span class="p">)</span>
<span class="go">&#39;tau = ((x &gt; 0).*(x + 1) + (~(x &gt; 0)).*(x));&#39;</span>
</pre></div>
</div>
<p>Note that any expression that can be generated normally can also exist
inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">pw</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
<span class="go">&#39;A = [x.^2 ((x &gt; 0).*(x + 1) + (~(x &gt; 0)).*(x)) sin(x)];&#39;</span>
</pre></div>
</div>
<p>Custom printing can be defined for certain types by passing a dictionary of
“type” : “function” to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg.  Alternatively, the
dictionary value can be a list of tuples i.e., [(argument_test,
cfunction_string)].  This can be used to call a custom Octave function.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">g</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;g&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;f&quot;</span><span class="p">:</span> <span class="s2">&quot;existing_octave_fcn&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;g&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Matrix</span><span class="p">,</span> <span class="s2">&quot;my_mat_fcn&quot;</span><span class="p">),</span>
<span class="gp">... </span>        <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_Matrix</span><span class="p">,</span> <span class="s2">&quot;my_fcn&quot;</span><span class="p">)]</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">g</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">g</span><span class="p">(</span><span class="n">mat</span><span class="p">),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;existing_octave_fcn(x) + my_fcn(x) + my_mat_fcn([1 x])&#39;</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">octave_code</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;Dy(i) = (y(i + 1) - y(i))./(t(i + 1) - t(i));&#39;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.rust">
<span id="rust-code-printing"></span><h2>Rust code printing<a class="headerlink" href="#module-sympy.printing.rust" title="Permalink to this headline">¶</a></h2>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.rust.known_functions">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.rust.</span></span><span class="sig-name descname"><span class="pre">known_functions</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Abs':</span> <span class="pre">'abs',</span> <span class="pre">'Max':</span> <span class="pre">'max',</span> <span class="pre">'Min':</span> <span class="pre">'min',</span> <span class="pre">'Pow':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'recip',</span> <span class="pre">2),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'sqrt',</span> <span class="pre">2),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'sqrt().recip',</span> <span class="pre">2),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'cbrt',</span> <span class="pre">2),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'exp2',</span> <span class="pre">3),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'powi',</span> <span class="pre">1),</span> <span class="pre">(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'powf',</span> <span class="pre">1)],</span> <span class="pre">'acos':</span> <span class="pre">'acos',</span> <span class="pre">'acosh':</span> <span class="pre">'acosh',</span> <span class="pre">'asin':</span> <span class="pre">'asin',</span> <span class="pre">'asinh':</span> <span class="pre">'asinh',</span> <span class="pre">'atan':</span> <span class="pre">'atan',</span> <span class="pre">'atan2':</span> <span class="pre">'atan2',</span> <span class="pre">'atanh':</span> <span class="pre">'atanh',</span> <span class="pre">'ceiling':</span> <span class="pre">'ceil',</span> <span class="pre">'cos':</span> <span class="pre">'cos',</span> <span class="pre">'cosh':</span> <span class="pre">'cosh',</span> <span class="pre">'exp':</span> <span class="pre">[(&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;,</span> <span class="pre">'exp',</span> <span class="pre">2)],</span> <span class="pre">'floor':</span> <span class="pre">'floor',</span> <span class="pre">'log':</span> <span class="pre">'ln',</span> <span class="pre">'sign':</span> <span class="pre">'signum',</span> <span class="pre">'sin':</span> <span class="pre">'sin',</span> <span class="pre">'sinh':</span> <span class="pre">'sinh',</span> <span class="pre">'tan':</span> <span class="pre">'tan',</span> <span class="pre">'tanh':</span> <span class="pre">'tanh'}</span></em><a class="headerlink" href="#sympy.printing.rust.known_functions" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.rust.RustCodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.rust.</span></span><span class="sig-name descname"><span class="pre">RustCodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rust.py#L216-L501"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rust.RustCodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>A printer to convert python expressions to strings of Rust code</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.rust.RustCodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_rust_code'</span></em><a class="headerlink" href="#sympy.printing.rust.RustCodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.rust.RustCodePrinter.indent_code">
<span class="sig-name descname"><span class="pre">indent_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rust.py#L475-L501"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rust.RustCodePrinter.indent_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Accepts a string of code or a list of code lines</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.rust.rust_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.rust.</span></span><span class="sig-name descname"><span class="pre">rust_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/rust.py#L504-L613"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.rust.rust_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of Rust code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A sympy expression to be converted.</p>
</div></blockquote>
<p><strong>assign_to</strong> : optional</p>
<blockquote>
<div><p>When given, the argument is used as the name of the variable to which
the expression is assigned. Can be a string, <code class="docutils literal notranslate"><span class="pre">Symbol</span></code>,
<code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code>, or <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> type. This is helpful in case of
line-wrapping, or for expressions that generate multi-line statements.</p>
</div></blockquote>
<p><strong>precision</strong> : integer, optional</p>
<blockquote>
<div><p>The precision for numbers such as pi [default=15].</p>
</div></blockquote>
<p><strong>user_functions</strong> : dict, optional</p>
<blockquote>
<div><p>A dictionary where the keys are string representations of either
<code class="docutils literal notranslate"><span class="pre">FunctionClass</span></code> or <code class="docutils literal notranslate"><span class="pre">UndefinedFunction</span></code> instances and the values
are their desired C string representations. Alternatively, the
dictionary value can be a list of tuples i.e. [(argument_test,
cfunction_string)].  See below for examples.</p>
</div></blockquote>
<p><strong>dereference</strong> : iterable, optional</p>
<blockquote>
<div><p>An iterable of symbols that should be dereferenced in the printed code
expression. These would be values passed by address to the function.
For example, if <code class="docutils literal notranslate"><span class="pre">dereference=[a]</span></code>, the resulting code would print
<code class="docutils literal notranslate"><span class="pre">(*a)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">a</span></code>.</p>
</div></blockquote>
<p><strong>human</strong> : bool, optional</p>
<blockquote>
<div><p>If True, the result is a single string that may contain some constant
declarations for the number symbols. If False, the same information is
returned in a tuple of (symbols_to_declare, not_supported_functions,
code_text). [default=True].</p>
</div></blockquote>
<p><strong>contract: bool, optional</strong></p>
<blockquote>
<div><p>If True, <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> instances are assumed to obey tensor contraction
rules and the corresponding nested loops over indices are generated.
Setting contract=False will not generate loops, instead the user is
responsible to provide values for the indices in the code.
[default=True].</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">rust_code</span><span class="p">,</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">ceiling</span><span class="p">,</span> <span class="n">Abs</span><span class="p">,</span> <span class="n">Function</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">tau</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x, tau&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rust_code</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8*1.4142135623731*tau.powf(7_f64/2.0)&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rust_code</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">assign_to</span><span class="o">=</span><span class="s2">&quot;s&quot;</span><span class="p">)</span>
<span class="go">&#39;s = x.sin();&#39;</span>
</pre></div>
</div>
<p>Simple custom printing can be defined for certain types by passing a
dictionary of {“type” : “function”} to the <code class="docutils literal notranslate"><span class="pre">user_functions</span></code> kwarg.
Alternatively, the dictionary value can be a list of tuples i.e.
[(argument_test, cfunction_string)].</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">custom_functions</span> <span class="o">=</span> <span class="p">{</span>
<span class="gp">... </span>  <span class="s2">&quot;ceiling&quot;</span><span class="p">:</span> <span class="s2">&quot;CEIL&quot;</span><span class="p">,</span>
<span class="gp">... </span>  <span class="s2">&quot;Abs&quot;</span><span class="p">:</span> <span class="p">[(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;fabs&quot;</span><span class="p">,</span> <span class="mi">4</span><span class="p">),</span>
<span class="gp">... </span>          <span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">is_integer</span><span class="p">,</span> <span class="s2">&quot;ABS&quot;</span><span class="p">,</span> <span class="mi">4</span><span class="p">)],</span>
<span class="gp">... </span>  <span class="s2">&quot;func&quot;</span><span class="p">:</span> <span class="s2">&quot;f&quot;</span>
<span class="gp">... </span><span class="p">}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">func</span> <span class="o">=</span> <span class="n">Function</span><span class="p">(</span><span class="s1">&#39;func&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rust_code</span><span class="p">(</span><span class="n">func</span><span class="p">(</span><span class="n">Abs</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">ceiling</span><span class="p">(</span><span class="n">x</span><span class="p">)),</span> <span class="n">user_functions</span><span class="o">=</span><span class="n">custom_functions</span><span class="p">)</span>
<span class="go">&#39;(fabs(x) + x.CEIL()).f()&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> expressions are converted into conditionals. If an
<code class="docutils literal notranslate"><span class="pre">assign_to</span></code> variable is provided an if statement is created, otherwise
the ternary operator is used. Note that if the <code class="docutils literal notranslate"><span class="pre">Piecewise</span></code> lacks a
default term, represented by <code class="docutils literal notranslate"><span class="pre">(expr,</span> <span class="pre">True)</span></code> then an error will be thrown.
This is to prevent generating an expression that may not evaluate to
anything.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Piecewise</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">expr</span> <span class="o">=</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rust_code</span><span class="p">(</span><span class="n">expr</span><span class="p">,</span> <span class="n">tau</span><span class="p">))</span>
<span class="go">tau = if (x &gt; 0) {</span>
<span class="go">    x + 1</span>
<span class="go">} else {</span>
<span class="go">    x</span>
<span class="go">};</span>
</pre></div>
</div>
<p>Support for loops is provided through <code class="docutils literal notranslate"><span class="pre">Indexed</span></code> types. With
<code class="docutils literal notranslate"><span class="pre">contract=True</span></code> these expressions will be turned into loops, whereas
<code class="docutils literal notranslate"><span class="pre">contract=False</span></code> will just print the assignment expression that should be
looped over:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">IndexedBase</span><span class="p">,</span> <span class="n">Idx</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">len_y</span> <span class="o">=</span> <span class="mi">5</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Dy</span> <span class="o">=</span> <span class="n">IndexedBase</span><span class="p">(</span><span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">,))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">i</span> <span class="o">=</span> <span class="n">Idx</span><span class="p">(</span><span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="n">len_y</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span><span class="o">=</span><span class="n">Eq</span><span class="p">(</span><span class="n">Dy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">/</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">t</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">rust_code</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">rhs</span><span class="p">,</span> <span class="n">assign_to</span><span class="o">=</span><span class="n">e</span><span class="o">.</span><span class="n">lhs</span><span class="p">,</span> <span class="n">contract</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">&#39;Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);&#39;</span>
</pre></div>
</div>
<p>Matrices are also supported, but a <code class="docutils literal notranslate"><span class="pre">MatrixSymbol</span></code> of the same dimensions
must be provided to <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>. Note that any expression that can be
generated normally can also exist inside a Matrix:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">MatrixSymbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mat</span> <span class="o">=</span> <span class="n">Matrix</span><span class="p">([</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">Piecewise</span><span class="p">((</span><span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="kc">True</span><span class="p">)),</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">MatrixSymbol</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">rust_code</span><span class="p">(</span><span class="n">mat</span><span class="p">,</span> <span class="n">A</span><span class="p">))</span>
<span class="go">A = [x.powi(2), if (x &gt; 0) {</span>
<span class="go">    x + 1</span>
<span class="go">} else {</span>
<span class="go">    x</span>
<span class="go">}, x.sin()];</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.aesaracode">
<span id="aesara-code-printing"></span><h2>Aesara Code printing<a class="headerlink" href="#module-sympy.printing.aesaracode" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.AesaraPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.aesaracode.</span></span><span class="sig-name descname"><span class="pre">AesaraPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/aesaracode.py#L70-L304"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.aesaracode.AesaraPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Code printer which creates Aesara symbolic expression graphs.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>cache</strong> : dict</p>
<blockquote>
<div><p>Cache dictionary to use. If None (default) will use
the global cache. To create a printer which does not depend on or alter
global state pass an empty dictionary. Note: the dictionary is not
copied on initialization of the printer and will be updated in-place,
so using the same dict object when creating multiple printers or making
multiple calls to <a class="reference internal" href="#sympy.printing.aesaracode.aesara_code" title="sympy.printing.aesaracode.aesara_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">aesara_code()</span></code></a> or <a class="reference internal" href="#sympy.printing.aesaracode.aesara_function" title="sympy.printing.aesaracode.aesara_function"><code class="xref py py-func docutils literal notranslate"><span class="pre">aesara_function()</span></code></a> means
the cache is shared between all these applications.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Attributes</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 1%" />
<col style="width: 99%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p>cache</p></td>
<td><p>(dict) A cache of Aesara variables which have been created for Sympy symbol-like objects (e.g. <a class="reference internal" href="core.html#sympy.core.symbol.Symbol" title="sympy.core.symbol.Symbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.core.symbol.Symbol</span></code></a> or <a class="reference internal" href="matrices/expressions.html#sympy.matrices.expressions.MatrixSymbol" title="sympy.matrices.expressions.MatrixSymbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">sympy.matrices.expressions.MatrixSymbol</span></code></a>). This is used to ensure that all references to a given symbol in an expression (or multiple expressions) are printed as the same Aesara variable, which is created only once. Symbols are differentiated only by name and type. The format of the cache’s contents should be considered opaque to the user.</p></td>
</tr>
</tbody>
</table>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.AesaraPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_aesara'</span></em><a class="headerlink" href="#sympy.printing.aesaracode.AesaraPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.AesaraPrinter.doprint">
<span class="sig-name descname"><span class="pre">doprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dtypes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">broadcastables</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/aesaracode.py#L259-L304"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a Sympy expression to a Aesara graph variable.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">dtypes</span></code> and <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> arguments are used to specify the
data type, dimension, and broadcasting behavior of the Aesara variables
corresponding to the free symbols in <code class="docutils literal notranslate"><span class="pre">expr</span></code>. Each is a mapping from
Sympy symbols to the value of the corresponding argument to
<code class="docutils literal notranslate"><span class="pre">aesara.tensor.var.TensorVariable</span></code>.</p>
<p>See the corresponding <a class="reference external" href="https://aesara.readthedocs.io/en/latest/tutorial/broadcasting.html">documentation page</a> for more information on
broadcasting in Aesara.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : sympy.core.expr.Expr</p>
<blockquote>
<div><p>Sympy expression to print.</p>
</div></blockquote>
<p><strong>dtypes</strong> : dict</p>
<blockquote>
<div><p>Mapping from Sympy symbols to Aesara datatypes to use when creating
new Aesara variables for those symbols. Corresponds to the <code class="docutils literal notranslate"><span class="pre">dtype</span></code>
argument to <code class="docutils literal notranslate"><span class="pre">aesara.tensor.var.TensorVariable</span></code>. Defaults to <code class="docutils literal notranslate"><span class="pre">'floatX'</span></code>
for symbols not included in the mapping.</p>
</div></blockquote>
<p><strong>broadcastables</strong> : dict</p>
<blockquote>
<div><p>Mapping from Sympy symbols to the value of the <code class="docutils literal notranslate"><span class="pre">broadcastable</span></code>
argument to <code class="docutils literal notranslate"><span class="pre">aesara.tensor.var.TensorVariable</span></code> to use when creating Aesara
variables for those symbols. Defaults to the empty tuple for symbols
not included in the mapping (resulting in a scalar).</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>aesara.graph.basic.Variable</p>
<blockquote>
<div><p>A variable corresponding to the expression’s value in a Aesara
symbolic expression graph.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.aesara_code">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.aesaracode.</span></span><span class="sig-name descname"><span class="pre">aesara_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cache</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/aesaracode.py#L310-L344"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.aesaracode.aesara_code" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a Sympy expression into a Aesara graph variable.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : sympy.core.expr.Expr</p>
<blockquote>
<div><p>Sympy expression object to convert.</p>
</div></blockquote>
<p><strong>cache</strong> : dict</p>
<blockquote>
<div><p>Cached Aesara variables (see <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter" title="sympy.printing.aesaracode.AesaraPrinter"><code class="xref py py-class docutils literal notranslate"><span class="pre">AesaraPrinter.cache</span></code></a>). Defaults to the module-level global cache.</p>
</div></blockquote>
<p><strong>dtypes</strong> : dict</p>
<blockquote>
<div><p>Passed to <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="sympy.printing.aesaracode.AesaraPrinter.doprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AesaraPrinter.doprint()</span></code></a>.</p>
</div></blockquote>
<p><strong>broadcastables</strong> : dict</p>
<blockquote>
<div><p>Passed to <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="sympy.printing.aesaracode.AesaraPrinter.doprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AesaraPrinter.doprint()</span></code></a>.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>aesara.graph.basic.Variable</p>
<blockquote>
<div><p>A variable corresponding to the expression’s value in a Aesara symbolic
expression graph.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.aesara_function">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.aesaracode.</span></span><span class="sig-name descname"><span class="pre">aesara_function</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">inputs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">outputs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scalar</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dims</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">broadcastables</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/aesaracode.py#L394-L529"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.aesaracode.aesara_function" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Aesara function from SymPy expressions.</p>
<p>The inputs and outputs are converted to Aesara variables using
<a class="reference internal" href="#sympy.printing.aesaracode.aesara_code" title="sympy.printing.aesaracode.aesara_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">aesara_code()</span></code></a> and then passed to <code class="docutils literal notranslate"><span class="pre">aesara.function</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>inputs</strong></p>
<blockquote>
<div><p>Sequence of symbols which constitute the inputs of the function.</p>
</div></blockquote>
<p><strong>outputs</strong></p>
<blockquote>
<div><p>Sequence of expressions which constitute the outputs(s) of the
function. The free symbols of each expression must be a subset of
<code class="docutils literal notranslate"><span class="pre">inputs</span></code>.</p>
</div></blockquote>
<p><strong>scalar</strong> : bool</p>
<blockquote>
<div><p>Convert 0-dimensional arrays in output to scalars. This will return a
Python wrapper function around the Aesara function object.</p>
</div></blockquote>
<p><strong>cache</strong> : dict</p>
<blockquote>
<div><p>Cached Aesara variables (see <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter" title="sympy.printing.aesaracode.AesaraPrinter"><code class="xref py py-class docutils literal notranslate"><span class="pre">AesaraPrinter.cache</span></code></a>). Defaults to the module-level global cache.</p>
</div></blockquote>
<p><strong>dtypes</strong> : dict</p>
<blockquote>
<div><p>Passed to <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="sympy.printing.aesaracode.AesaraPrinter.doprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AesaraPrinter.doprint()</span></code></a>.</p>
</div></blockquote>
<p><strong>broadcastables</strong> : dict</p>
<blockquote>
<div><p>Passed to <a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="sympy.printing.aesaracode.AesaraPrinter.doprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AesaraPrinter.doprint()</span></code></a>.</p>
</div></blockquote>
<p><strong>dims</strong> : dict</p>
<blockquote>
<div><p>Alternative to <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument. Mapping from elements of
<code class="docutils literal notranslate"><span class="pre">inputs</span></code> to integers indicating the dimension of their associated
arrays/tensors. Overrides <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument if given.</p>
</div></blockquote>
<p><strong>dim</strong> : int</p>
<blockquote>
<div><p>Another alternative to the <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument. Common number of
dimensions to use for all arrays/tensors.
<code class="docutils literal notranslate"><span class="pre">aesara_function([x,</span> <span class="pre">y],</span> <span class="pre">[...],</span> <span class="pre">dim=2)</span></code> is equivalent to using
<code class="docutils literal notranslate"><span class="pre">broadcastables={x:</span> <span class="pre">(False,</span> <span class="pre">False),</span> <span class="pre">y:</span> <span class="pre">(False,</span> <span class="pre">False)}</span></code>.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>callable</p>
<blockquote>
<div><p>A callable object which takes values of <code class="docutils literal notranslate"><span class="pre">inputs</span></code> as positional
arguments and returns an output array for each of the expressions
in <code class="docutils literal notranslate"><span class="pre">outputs</span></code>. If <code class="docutils literal notranslate"><span class="pre">outputs</span></code> is a single expression the function will
return a Numpy array, if it is a list of multiple expressions the
function will return a list of arrays. See description of the <code class="docutils literal notranslate"><span class="pre">squeeze</span></code>
argument above for the behavior when a single output is passed in a list.
The returned object will either be an instance of
<code class="docutils literal notranslate"><span class="pre">aesara.compile.function.types.Function</span></code> or a Python wrapper
function around one. In both cases, the returned value will have a
<code class="docutils literal notranslate"><span class="pre">aesara_function</span></code> attribute which points to the return value of
<code class="docutils literal notranslate"><span class="pre">aesara.function</span></code>.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.aesaracode</span> <span class="kn">import</span> <span class="n">aesara_function</span>
</pre></div>
</div>
<p>A simple function with one input and one output:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f1</span> <span class="o">=</span> <span class="n">aesara_function</span><span class="p">([</span><span class="n">x</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">1</span><span class="p">],</span> <span class="n">scalar</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f1</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">8.0</span>
</pre></div>
</div>
<p>A function with multiple inputs and one output:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f2</span> <span class="o">=</span> <span class="n">aesara_function</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">],</span> <span class="p">[(</span><span class="n">x</span><span class="o">**</span><span class="n">z</span> <span class="o">+</span> <span class="n">y</span><span class="o">**</span><span class="n">z</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">z</span><span class="p">)],</span> <span class="n">scalar</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f2</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">5.0</span>
</pre></div>
</div>
<p>A function with multiple inputs and multiple outputs:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">f3</span> <span class="o">=</span> <span class="n">aesara_function</span><span class="p">([</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="p">[</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="n">y</span><span class="o">**</span><span class="mi">2</span><span class="p">],</span> <span class="n">scalar</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f3</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="go">[13.0, -5.0]</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.printing.aesaracode.dim_handling" title="sympy.printing.aesaracode.dim_handling"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dim_handling</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.aesaracode.dim_handling">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.aesaracode.</span></span><span class="sig-name descname"><span class="pre">dim_handling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">inputs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dims</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">broadcastables</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/aesaracode.py#L347-L391"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.aesaracode.dim_handling" title="Permalink to this definition">¶</a></dt>
<dd><p>Get value of <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument to <a class="reference internal" href="#sympy.printing.aesaracode.aesara_code" title="sympy.printing.aesaracode.aesara_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">aesara_code()</span></code></a> from
keyword arguments to <a class="reference internal" href="#sympy.printing.aesaracode.aesara_function" title="sympy.printing.aesaracode.aesara_function"><code class="xref py py-func docutils literal notranslate"><span class="pre">aesara_function()</span></code></a>.</p>
<p>Included for backwards compatibility.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>inputs</strong></p>
<blockquote>
<div><p>Sequence of input symbols.</p>
</div></blockquote>
<p><strong>dim</strong> : int</p>
<blockquote>
<div><p>Common number of dimensions for all inputs. Overrides other arguments
if given.</p>
</div></blockquote>
<p><strong>dims</strong> : dict</p>
<blockquote>
<div><p>Mapping from input symbols to number of dimensions. Overrides
<code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument if given.</p>
</div></blockquote>
<p><strong>broadcastables</strong> : dict</p>
<blockquote>
<div><p>Explicit value of <code class="docutils literal notranslate"><span class="pre">broadcastables</span></code> argument to
<a class="reference internal" href="#sympy.printing.aesaracode.AesaraPrinter.doprint" title="sympy.printing.aesaracode.AesaraPrinter.doprint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AesaraPrinter.doprint()</span></code></a>. If not None function will return this value unchanged.</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>dict</p>
<blockquote>
<div><p>Dictionary mapping elements of <code class="docutils literal notranslate"><span class="pre">inputs</span></code> to their “broadcastable”
values (tuple of <code class="docutils literal notranslate"><span class="pre">bool</span></code>s).</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</section>
<section id="module-sympy.printing.gtk">
<span id="gtk"></span><h2>Gtk<a class="headerlink" href="#module-sympy.printing.gtk" title="Permalink to this headline">¶</a></h2>
<p>You can print to a gtkmathview widget using the function <code class="docutils literal notranslate"><span class="pre">print_gtk</span></code>
located in <code class="docutils literal notranslate"><span class="pre">sympy.printing.gtk</span></code> (it requires to have installed
gtkmathview and libgtkmathview-bin in some systems).</p>
<p>GtkMathView accepts MathML, so this rendering depends on the MathML
representation of the expression.</p>
<p>Usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">print_gtk</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span><span class="p">))</span>
</pre></div>
</div>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.gtk.print_gtk">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.gtk.</span></span><span class="sig-name descname"><span class="pre">print_gtk</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">start_viewer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/gtk.py#L7-L16"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.gtk.print_gtk" title="Permalink to this definition">¶</a></dt>
<dd><p>Print to Gtkmathview, a gtk widget capable of rendering MathML.</p>
<p>Needs libgtkmathview-bin</p>
</dd></dl>

</section>
<section id="module-sympy.printing.lambdarepr">
<span id="lambdaprinter"></span><h2>LambdaPrinter<a class="headerlink" href="#module-sympy.printing.lambdarepr" title="Permalink to this headline">¶</a></h2>
<p>This classes implements printing to strings that can be used by the
<a class="reference internal" href="utilities/lambdify.html#sympy.utilities.lambdify.lambdify" title="sympy.utilities.lambdify.lambdify"><code class="xref py py-func docutils literal notranslate"><span class="pre">sympy.utilities.lambdify.lambdify()</span></code></a> function.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.lambdarepr.LambdaPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.lambdarepr.</span></span><span class="sig-name descname"><span class="pre">LambdaPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/lambdarepr.py#L19-L69"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.lambdarepr.LambdaPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>This printer converts expressions into strings that can be used by
lambdify.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.lambdarepr.LambdaPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_lambdacode'</span></em><a class="headerlink" href="#sympy.printing.lambdarepr.LambdaPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.lambdarepr.lambdarepr">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.lambdarepr.</span></span><span class="sig-name descname"><span class="pre">lambdarepr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/lambdarepr.py#L189-L193"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.lambdarepr.lambdarepr" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a string usable for lambdifying.</p>
</dd></dl>

</section>
<section id="module-sympy.printing.latex">
<span id="latexprinter"></span><h2>LatexPrinter<a class="headerlink" href="#module-sympy.printing.latex" title="Permalink to this headline">¶</a></h2>
<p>This class implements LaTeX printing. See <code class="docutils literal notranslate"><span class="pre">sympy.printing.latex</span></code>.</p>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.latex.accepted_latex_functions">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.latex.</span></span><span class="sig-name descname"><span class="pre">accepted_latex_functions</span></span><em class="property"> <span class="pre">=</span> <span class="pre">['arcsin',</span> <span class="pre">'arccos',</span> <span class="pre">'arctan',</span> <span class="pre">'sin',</span> <span class="pre">'cos',</span> <span class="pre">'tan',</span> <span class="pre">'sinh',</span> <span class="pre">'cosh',</span> <span class="pre">'tanh',</span> <span class="pre">'sqrt',</span> <span class="pre">'ln',</span> <span class="pre">'log',</span> <span class="pre">'sec',</span> <span class="pre">'csc',</span> <span class="pre">'cot',</span> <span class="pre">'coth',</span> <span class="pre">'re',</span> <span class="pre">'im',</span> <span class="pre">'frac',</span> <span class="pre">'root',</span> <span class="pre">'arg']</span></em><a class="headerlink" href="#sympy.printing.latex.accepted_latex_functions" title="Permalink to this definition">¶</a></dt>
<dd><p>Built-in mutable sequence.</p>
<p>If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.latex.LatexPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.latex.</span></span><span class="sig-name descname"><span class="pre">LatexPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/latex.py#L137-L2747"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.latex.LatexPrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.latex.LatexPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_latex'</span></em><a class="headerlink" href="#sympy.printing.latex.LatexPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.latex.LatexPrinter.parenthesize_super">
<span class="sig-name descname"><span class="pre">parenthesize_super</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/latex.py#L239-L251"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.latex.LatexPrinter.parenthesize_super" title="Permalink to this definition">¶</a></dt>
<dd><p>Protect superscripts in s</p>
<p>If the parenthesize_super option is set, protect with parentheses, else
wrap in braces.</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.latex.latex">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.latex.</span></span><span class="sig-name descname"><span class="pre">latex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full_prec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_frac_powers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_func_brackets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_short_frac</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inv_trig_style</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'abbreviated'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">itex</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ln_notation</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">long_frac_ratio</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_delim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'['</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_str</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'plain'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mul_symbol</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbol_names</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">root_notation</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_symbol_style</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'plain'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">imaginary_unit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'i'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gothic_re_im</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decimal_separator</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'period'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm_cyclic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parenthesize_super</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/latex.py#L2781-L2985"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.latex.latex" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the given expression to LaTeX string representation.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>full_prec: boolean, optional</strong></p>
<blockquote>
<div><p>If set to True, a floating point number is printed with full precision.</p>
</div></blockquote>
<p><strong>fold_frac_powers</strong> : boolean, optional</p>
<blockquote>
<div><p>Emit <code class="docutils literal notranslate"><span class="pre">^{p/q}</span></code> instead of <code class="docutils literal notranslate"><span class="pre">^{\frac{p}{q}}</span></code> for fractional powers.</p>
</div></blockquote>
<p><strong>fold_func_brackets</strong> : boolean, optional</p>
<blockquote>
<div><p>Fold function brackets where applicable.</p>
</div></blockquote>
<p><strong>fold_short_frac</strong> : boolean, optional</p>
<blockquote>
<div><p>Emit <code class="docutils literal notranslate"><span class="pre">p</span> <span class="pre">/</span> <span class="pre">q</span></code> instead of <code class="docutils literal notranslate"><span class="pre">\frac{p}{q}</span></code> when the denominator is
simple enough (at most two terms and no powers). The default value is
<code class="docutils literal notranslate"><span class="pre">True</span></code> for inline mode, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p>
</div></blockquote>
<p><strong>inv_trig_style</strong> : string, optional</p>
<blockquote>
<div><p>How inverse trig functions should be displayed. Can be one of
<code class="docutils literal notranslate"><span class="pre">abbreviated</span></code>, <code class="docutils literal notranslate"><span class="pre">full</span></code>, or <code class="docutils literal notranslate"><span class="pre">power</span></code>. Defaults to <code class="docutils literal notranslate"><span class="pre">abbreviated</span></code>.</p>
</div></blockquote>
<p><strong>itex</strong> : boolean, optional</p>
<blockquote>
<div><p>Specifies if itex-specific syntax is used, including emitting
<code class="docutils literal notranslate"><span class="pre">$$...$$</span></code>.</p>
</div></blockquote>
<p><strong>ln_notation</strong> : boolean, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="docutils literal notranslate"><span class="pre">\ln</span></code> is used instead of default <code class="docutils literal notranslate"><span class="pre">\log</span></code>.</p>
</div></blockquote>
<p><strong>long_frac_ratio</strong> : float or None, optional</p>
<blockquote>
<div><p>The allowed ratio of the width of the numerator to the width of the
denominator before the printer breaks off long fractions. If <code class="docutils literal notranslate"><span class="pre">None</span></code>
(the default value), long fractions are not broken up.</p>
</div></blockquote>
<p><strong>mat_delim</strong> : string, optional</p>
<blockquote>
<div><p>The delimiter to wrap around matrices. Can be one of <code class="docutils literal notranslate"><span class="pre">[</span></code>, <code class="docutils literal notranslate"><span class="pre">(</span></code>, or
the empty string. Defaults to <code class="docutils literal notranslate"><span class="pre">[</span></code>.</p>
</div></blockquote>
<p><strong>mat_str</strong> : string, optional</p>
<blockquote>
<div><p>Which matrix environment string to emit. <code class="docutils literal notranslate"><span class="pre">smallmatrix</span></code>, <code class="docutils literal notranslate"><span class="pre">matrix</span></code>,
<code class="docutils literal notranslate"><span class="pre">array</span></code>, etc. Defaults to <code class="docutils literal notranslate"><span class="pre">smallmatrix</span></code> for inline mode, <code class="docutils literal notranslate"><span class="pre">matrix</span></code>
for matrices of no more than 10 columns, and <code class="docutils literal notranslate"><span class="pre">array</span></code> otherwise.</p>
</div></blockquote>
<p><strong>mode: string, optional</strong></p>
<blockquote>
<div><p>Specifies how the generated code will be delimited. <code class="docutils literal notranslate"><span class="pre">mode</span></code> can be one
of <code class="docutils literal notranslate"><span class="pre">plain</span></code>, <code class="docutils literal notranslate"><span class="pre">inline</span></code>, <code class="docutils literal notranslate"><span class="pre">equation</span></code> or <code class="docutils literal notranslate"><span class="pre">equation*</span></code>.  If <code class="docutils literal notranslate"><span class="pre">mode</span></code>
is set to <code class="docutils literal notranslate"><span class="pre">plain</span></code>, then the resulting code will not be delimited at
all (this is the default). If <code class="docutils literal notranslate"><span class="pre">mode</span></code> is set to <code class="docutils literal notranslate"><span class="pre">inline</span></code> then inline
LaTeX <code class="docutils literal notranslate"><span class="pre">$...$</span></code> will be used. If <code class="docutils literal notranslate"><span class="pre">mode</span></code> is set to <code class="docutils literal notranslate"><span class="pre">equation</span></code> or
<code class="docutils literal notranslate"><span class="pre">equation*</span></code>, the resulting code will be enclosed in the <code class="docutils literal notranslate"><span class="pre">equation</span></code>
or <code class="docutils literal notranslate"><span class="pre">equation*</span></code> environment (remember to import <code class="docutils literal notranslate"><span class="pre">amsmath</span></code> for
<code class="docutils literal notranslate"><span class="pre">equation*</span></code>), unless the <code class="docutils literal notranslate"><span class="pre">itex</span></code> option is set. In the latter case,
the <code class="docutils literal notranslate"><span class="pre">$$...$$</span></code> syntax is used.</p>
</div></blockquote>
<p><strong>mul_symbol</strong> : string or None, optional</p>
<blockquote>
<div><p>The symbol to use for multiplication. Can be one of <code class="docutils literal notranslate"><span class="pre">None</span></code>, <code class="docutils literal notranslate"><span class="pre">ldot</span></code>,
<code class="docutils literal notranslate"><span class="pre">dot</span></code>, or <code class="docutils literal notranslate"><span class="pre">times</span></code>.</p>
</div></blockquote>
<p><strong>order: string, optional</strong></p>
<blockquote>
<div><p>Any of the supported monomial orderings (currently <code class="docutils literal notranslate"><span class="pre">lex</span></code>, <code class="docutils literal notranslate"><span class="pre">grlex</span></code>,
or <code class="docutils literal notranslate"><span class="pre">grevlex</span></code>), <code class="docutils literal notranslate"><span class="pre">old</span></code>, and <code class="docutils literal notranslate"><span class="pre">none</span></code>. This parameter does nothing for
Mul objects. Setting order to <code class="docutils literal notranslate"><span class="pre">old</span></code> uses the compatibility ordering
for Add defined in Printer. For very large expressions, set the
<code class="docutils literal notranslate"><span class="pre">order</span></code> keyword to <code class="docutils literal notranslate"><span class="pre">none</span></code> if speed is a concern.</p>
</div></blockquote>
<p><strong>symbol_names</strong> : dictionary of strings mapped to symbols, optional</p>
<blockquote>
<div><p>Dictionary of symbols and the custom strings they should be emitted as.</p>
</div></blockquote>
<p><strong>root_notation</strong> : boolean, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, exponents of the form 1/n are printed in fractonal
form. Default is <code class="docutils literal notranslate"><span class="pre">True</span></code>, to print exponent in root form.</p>
</div></blockquote>
<p><strong>mat_symbol_style</strong> : string, optional</p>
<blockquote>
<div><p>Can be either <code class="docutils literal notranslate"><span class="pre">plain</span></code> (default) or <code class="docutils literal notranslate"><span class="pre">bold</span></code>. If set to <code class="docutils literal notranslate"><span class="pre">bold</span></code>,
a MatrixSymbol A will be printed as <code class="docutils literal notranslate"><span class="pre">\mathbf{A}</span></code>, otherwise as <code class="docutils literal notranslate"><span class="pre">A</span></code>.</p>
</div></blockquote>
<p><strong>imaginary_unit</strong> : string, optional</p>
<blockquote>
<div><p>String to use for the imaginary unit. Defined options are “i” (default)
and “j”. Adding “r” or “t” in front gives <code class="docutils literal notranslate"><span class="pre">\mathrm</span></code> or <code class="docutils literal notranslate"><span class="pre">\text</span></code>, so
“ri” leads to <code class="docutils literal notranslate"><span class="pre">\mathrm{i}</span></code> which gives <span class="math notranslate nohighlight">\(\mathrm{i}\)</span>.</p>
</div></blockquote>
<p><strong>gothic_re_im</strong> : boolean, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, <span class="math notranslate nohighlight">\(\Re\)</span> and <span class="math notranslate nohighlight">\(\Im\)</span> is used for <code class="docutils literal notranslate"><span class="pre">re</span></code> and <code class="docutils literal notranslate"><span class="pre">im</span></code>, respectively.
The default is <code class="docutils literal notranslate"><span class="pre">False</span></code> leading to <span class="math notranslate nohighlight">\(\operatorname{re}\)</span> and <span class="math notranslate nohighlight">\(\operatorname{im}\)</span>.</p>
</div></blockquote>
<p><strong>decimal_separator</strong> : string, optional</p>
<blockquote>
<div><p>Specifies what separator to use to separate the whole and fractional parts of a
floating point number as in <span class="math notranslate nohighlight">\(2.5\)</span> for the default, <code class="docutils literal notranslate"><span class="pre">period</span></code> or <span class="math notranslate nohighlight">\(2{,}5\)</span>
when <code class="docutils literal notranslate"><span class="pre">comma</span></code> is specified. Lists, sets, and tuple are printed with semicolon
separating the elements when <code class="docutils literal notranslate"><span class="pre">comma</span></code> is chosen. For example, [1; 2; 3] when
<code class="docutils literal notranslate"><span class="pre">comma</span></code> is chosen and [1,2,3] for when <code class="docutils literal notranslate"><span class="pre">period</span></code> is chosen.</p>
</div></blockquote>
<p><strong>parenthesize_super</strong> : boolean, optional</p>
<blockquote>
<div><p>If set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, superscripted expressions will not be parenthesized when
powered. Default is <code class="docutils literal notranslate"><span class="pre">True</span></code>, which parenthesizes the expression when powered.</p>
</div></blockquote>
<p><strong>min: Integer or None, optional</strong></p>
<blockquote>
<div><p>Sets the lower bound for the exponent to print floating point numbers in
fixed-point format.</p>
</div></blockquote>
<p><strong>max: Integer or None, optional</strong></p>
<blockquote>
<div><p>Sets the upper bound for the exponent to print floating point numbers in
fixed-point format.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Notes</p>
<p>Not using a print statement for printing, results in double backslashes for
latex commands since that’s the way Python escapes backslashes in strings.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">latex</span><span class="p">,</span> <span class="n">Rational</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">tau</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span>
<span class="go">&#39;8 \\sqrt{2} \\tau^{\\frac{7}{2}}&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)))</span>
<span class="go">8 \sqrt{2} \tau^{\frac{7}{2}}</span>
</pre></div>
</div>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">latex</span><span class="p">,</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">asin</span><span class="p">,</span> <span class="n">Integral</span><span class="p">,</span> <span class="n">Matrix</span><span class="p">,</span> <span class="n">Rational</span><span class="p">,</span> <span class="n">log</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">mu</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">tau</span>
</pre></div>
</div>
<p>Basic usage:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)))</span>
<span class="go">8 \sqrt{2} \tau^{\frac{7}{2}}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">mode</span></code> and <code class="docutils literal notranslate"><span class="pre">itex</span></code> options:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;plain&#39;</span><span class="p">))</span>
<span class="go">8 \sqrt{2} \mu^{\frac{7}{2}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;inline&#39;</span><span class="p">))</span>
<span class="go">$8 \sqrt{2} \tau^{7 / 2}$</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation*&#39;</span><span class="p">))</span>
<span class="go">\begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation&#39;</span><span class="p">))</span>
<span class="go">\begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation&#39;</span><span class="p">,</span> <span class="n">itex</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">$$8 \sqrt{2} \mu^{\frac{7}{2}}$$</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;plain&#39;</span><span class="p">))</span>
<span class="go">8 \sqrt{2} \mu^{\frac{7}{2}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;inline&#39;</span><span class="p">))</span>
<span class="go">$8 \sqrt{2} \tau^{7 / 2}$</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation*&#39;</span><span class="p">))</span>
<span class="go">\begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation&#39;</span><span class="p">))</span>
<span class="go">\begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">mu</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;equation&#39;</span><span class="p">,</span> <span class="n">itex</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">$$8 \sqrt{2} \mu^{\frac{7}{2}}$$</span>
</pre></div>
</div>
<p>Fraction options:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">),</span> <span class="n">fold_frac_powers</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">8 \sqrt{2} \tau^{7/2}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">sin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">))))</span>
<span class="go">\left(2 \tau\right)^{\sin{\left(\frac{7}{2} \right)}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">sin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)),</span> <span class="n">fold_func_brackets</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">\left(2 \tau\right)^{\sin {\frac{7}{2}}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="n">y</span><span class="p">))</span>
<span class="go">\frac{3 x^{2}}{y}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="o">/</span><span class="n">y</span><span class="p">,</span> <span class="n">fold_short_frac</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">3 x^{2} / y</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">Integral</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="o">/</span><span class="n">pi</span><span class="p">,</span> <span class="n">long_frac_ratio</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span>
<span class="go">\frac{\int r\, dr}{2 \pi}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">Integral</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="o">/</span><span class="n">pi</span><span class="p">,</span> <span class="n">long_frac_ratio</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
<span class="go">\frac{1}{2 \pi} \int r\, dr</span>
</pre></div>
</div>
<p>Multiplication options:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">((</span><span class="mi">2</span><span class="o">*</span><span class="n">tau</span><span class="p">)</span><span class="o">**</span><span class="n">sin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)),</span> <span class="n">mul_symbol</span><span class="o">=</span><span class="s2">&quot;times&quot;</span><span class="p">))</span>
<span class="go">\left(2 \times \tau\right)^{\sin{\left(\frac{7}{2} \right)}}</span>
</pre></div>
</div>
<p>Trig options:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">asin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">))))</span>
<span class="go">\operatorname{asin}{\left(\frac{7}{2} \right)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">asin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)),</span> <span class="n">inv_trig_style</span><span class="o">=</span><span class="s2">&quot;full&quot;</span><span class="p">))</span>
<span class="go">\arcsin{\left(\frac{7}{2} \right)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">asin</span><span class="p">(</span><span class="n">Rational</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">2</span><span class="p">)),</span> <span class="n">inv_trig_style</span><span class="o">=</span><span class="s2">&quot;power&quot;</span><span class="p">))</span>
<span class="go">\sin^{-1}{\left(\frac{7}{2} \right)}</span>
</pre></div>
</div>
<p>Matrix options:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">])))</span>
<span class="go">\left[\begin{matrix}x\\y\end{matrix}\right]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">]),</span> <span class="n">mat_str</span> <span class="o">=</span> <span class="s2">&quot;array&quot;</span><span class="p">))</span>
<span class="go">\left[\begin{array}{c}x\\y\end{array}\right]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">Matrix</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">]),</span> <span class="n">mat_delim</span><span class="o">=</span><span class="s2">&quot;(&quot;</span><span class="p">))</span>
<span class="go">\left(\begin{matrix}x\\y\end{matrix}\right)</span>
</pre></div>
</div>
<p>Custom printing of symbols:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">symbol_names</span><span class="o">=</span><span class="p">{</span><span class="n">x</span><span class="p">:</span> <span class="s1">&#39;x_i&#39;</span><span class="p">}))</span>
<span class="go">x_i^{2}</span>
</pre></div>
</div>
<p>Logarithms:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="mi">10</span><span class="p">)))</span>
<span class="go">\log{\left(10 \right)}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="n">log</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">ln_notation</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
<span class="go">\ln{\left(10 \right)}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">latex()</span></code> also supports the builtin container types <code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code>,
<code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code>, and <code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code>:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">([</span><span class="mi">2</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">],</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;inline&#39;</span><span class="p">))</span>
<span class="go">$\left[ 2 / x, \  y\right]$</span>
</pre></div>
</div>
<p>Unsupported types are rendered as monospaced plaintext:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="nb">int</span><span class="p">))</span>
<span class="go">\mathtt{\text{&lt;class &#39;int&#39;&gt;}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">latex</span><span class="p">(</span><span class="s2">&quot;plain % text&quot;</span><span class="p">))</span>
<span class="go">\mathtt{\text{plain \% text}}</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="#printer-method-example"><span class="std std-ref">Example of Custom Printing Method</span></a> for an example of how to override
this behavior for your own types by implementing <code class="docutils literal notranslate"><span class="pre">_latex</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 1.7.0: </span>Unsupported types no longer have their <code class="docutils literal notranslate"><span class="pre">str</span></code> representation treated as valid latex.</p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.latex.print_latex">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.latex.</span></span><span class="sig-name descname"><span class="pre">print_latex</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/latex.py#L2988-L2992"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.latex.print_latex" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints LaTeX representation of the given expression. Takes the same
settings as <code class="docutils literal notranslate"><span class="pre">latex()</span></code>.</p>
</dd></dl>

</section>
<section id="module-sympy.printing.mathml">
<span id="mathmlprinter"></span><h2>MathMLPrinter<a class="headerlink" href="#module-sympy.printing.mathml" title="Permalink to this headline">¶</a></h2>
<p>This class is responsible for MathML printing. See <code class="docutils literal notranslate"><span class="pre">sympy.printing.mathml</span></code>.</p>
<p>More info on mathml : <a class="reference external" href="http://www.w3.org/TR/MathML2">http://www.w3.org/TR/MathML2</a></p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLPrinterBase">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.mathml.</span></span><span class="sig-name descname"><span class="pre">MathMLPrinterBase</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L20-L124"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLPrinterBase" title="Permalink to this definition">¶</a></dt>
<dd><p>Contains common code required for MathMLContentPrinter and
MathMLPresentationPrinter.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLPrinterBase.doprint">
<span class="sig-name descname"><span class="pre">doprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L65-L73"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLPrinterBase.doprint" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints the expression as MathML.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLContentPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.mathml.</span></span><span class="sig-name descname"><span class="pre">MathMLContentPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L127-L576"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLContentPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints an expression to the Content MathML markup language.</p>
<p>References: <a class="reference external" href="https://www.w3.org/TR/MathML2/chapter4.html">https://www.w3.org/TR/MathML2/chapter4.html</a></p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLContentPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_mathml_content'</span></em><a class="headerlink" href="#sympy.printing.mathml.MathMLContentPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLContentPrinter.mathml_tag">
<span class="sig-name descname"><span class="pre">mathml_tag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L134-L198"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLContentPrinter.mathml_tag" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the MathML tag for an expression.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLPresentationPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.mathml.</span></span><span class="sig-name descname"><span class="pre">MathMLPresentationPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L579-L2073"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLPresentationPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints an expression to the Presentation MathML markup language.</p>
<p>References: <a class="reference external" href="https://www.w3.org/TR/MathML2/chapter3.html">https://www.w3.org/TR/MathML2/chapter3.html</a></p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLPresentationPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_mathml_presentation'</span></em><a class="headerlink" href="#sympy.printing.mathml.MathMLPresentationPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.mathml.MathMLPresentationPrinter.mathml_tag">
<span class="sig-name descname"><span class="pre">mathml_tag</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L586-L660"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.MathMLPresentationPrinter.mathml_tag" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the MathML tag for an expression.</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.mathml.mathml">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.mathml.</span></span><span class="sig-name descname"><span class="pre">mathml</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">printer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'content'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'utf-8'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_frac_powers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_func_brackets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fold_short_frac</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">inv_trig_style</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'abbreviated'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ln_notation</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">long_frac_ratio</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_delim</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'['</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mat_symbol_style</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'plain'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mul_symbol</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">root_notation</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">symbol_names</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">{}</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mul_symbol_mathml_numbers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'&amp;#xB7;'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L2076-L2084"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.mathml" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the MathML representation of expr. If printer is presentation
then prints Presentation MathML else prints content MathML.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.mathml.print_mathml">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.mathml.</span></span><span class="sig-name descname"><span class="pre">print_mathml</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">printer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'content'</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/mathml.py#L2087-L2121"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.mathml.print_mathml" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints a pretty representation of the MathML code for expr. If printer is
presentation then prints Presentation MathML else prints content MathML.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1">##</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.mathml</span> <span class="kn">import</span> <span class="n">print_mathml</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_mathml</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> 
<span class="go">&lt;apply&gt;</span>
<span class="go">    &lt;plus/&gt;</span>
<span class="go">    &lt;ci&gt;x&lt;/ci&gt;</span>
<span class="go">    &lt;cn&gt;1&lt;/cn&gt;</span>
<span class="go">&lt;/apply&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">print_mathml</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span> <span class="n">printer</span><span class="o">=</span><span class="s1">&#39;presentation&#39;</span><span class="p">)</span>
<span class="go">&lt;mrow&gt;</span>
<span class="go">    &lt;mi&gt;x&lt;/mi&gt;</span>
<span class="go">    &lt;mo&gt;+&lt;/mo&gt;</span>
<span class="go">    &lt;mn&gt;1&lt;/mn&gt;</span>
<span class="go">&lt;/mrow&gt;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.pycode">
<span id="pythoncodeprinter"></span><h2>PythonCodePrinter<a class="headerlink" href="#module-sympy.printing.pycode" title="Permalink to this headline">¶</a></h2>
<p>Python code printers</p>
<p>This module contains python code printers for plain python as well as NumPy &amp; SciPy enabled code.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.pycode.MpmathPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.pycode.</span></span><span class="sig-name descname"><span class="pre">MpmathPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pycode.py#L543-L608"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pycode.MpmathPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>Lambda printer for mpmath which maintains precision for floats</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pycode.pycode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pycode.</span></span><span class="sig-name descname"><span class="pre">pycode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pycode.py#L472-L499"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pycode.pycode" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts an expr to a string of Python code</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expr</p>
<blockquote>
<div><p>A SymPy expression.</p>
</div></blockquote>
<p><strong>fully_qualified_modules</strong> : bool</p>
<blockquote>
<div><p>Whether or not to write out full module names of functions
(<code class="docutils literal notranslate"><span class="pre">math.sin</span></code> vs. <code class="docutils literal notranslate"><span class="pre">sin</span></code>). default: <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
</div></blockquote>
<p><strong>standard</strong> : str or None, optional</p>
<blockquote>
<div><p>If ‘python2’, Python 2 sematics will be used.
If ‘python3’, Python 3 sematics will be used.
If None, the standard will be automatically detected.
Default is ‘python3’. And this parameter may be removed in the
future.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">tan</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.pycode</span> <span class="kn">import</span> <span class="n">pycode</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pycode</span><span class="p">(</span><span class="n">tan</span><span class="p">(</span><span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">))</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
<span class="go">&#39;math.tan(x) + 1&#39;</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.python">
<span id="pythonprinter"></span><h2>PythonPrinter<a class="headerlink" href="#module-sympy.printing.python" title="Permalink to this headline">¶</a></h2>
<p>This class implements Python printing. Usage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">print_python</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">print_python</span><span class="p">(</span><span class="mi">5</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">x = Symbol(&#39;x&#39;)</span>
<span class="go">e = 5*x**3 + sin(x)</span>
</pre></div>
</div>
</section>
<section id="module-sympy.printing.repr">
<span id="srepr"></span><h2>srepr<a class="headerlink" href="#module-sympy.printing.repr" title="Permalink to this headline">¶</a></h2>
<p>This printer generates executable code. This code satisfies the identity
<code class="docutils literal notranslate"><span class="pre">eval(srepr(expr))</span> <span class="pre">==</span> <span class="pre">expr</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">srepr()</span></code> gives more low level textual output than <code class="docutils literal notranslate"><span class="pre">repr()</span></code></p>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">repr</span><span class="p">(</span><span class="mi">5</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">&#39;5*x**3 + sin(x)&#39;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">srepr</span><span class="p">(</span><span class="mi">5</span><span class="o">*</span><span class="n">x</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">&quot;Add(Mul(Integer(5), Pow(Symbol(&#39;x&#39;), Integer(3))), sin(Symbol(&#39;x&#39;)))&quot;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">srepr()</span></code> gives the <code class="docutils literal notranslate"><span class="pre">repr</span></code> form, which is what <code class="docutils literal notranslate"><span class="pre">repr()</span></code> would normally give
but for SymPy we don’t actually use <code class="docutils literal notranslate"><span class="pre">srepr()</span></code> for <code class="docutils literal notranslate"><span class="pre">__repr__</span></code> because it’s
is so verbose, it is unlikely that anyone would want it called by default.
Another reason is that lists call repr on their elements, like <code class="docutils literal notranslate"><span class="pre">print([a,</span> <span class="pre">b,</span> <span class="pre">c])</span></code>
calls <code class="docutils literal notranslate"><span class="pre">repr(a)</span></code>, <code class="docutils literal notranslate"><span class="pre">repr(b)</span></code>, <code class="docutils literal notranslate"><span class="pre">repr(c)</span></code>. So if we used srepr for `` __repr__`` any list with
SymPy objects would include the srepr form, even if we used <code class="docutils literal notranslate"><span class="pre">str()</span></code> or <code class="docutils literal notranslate"><span class="pre">print()</span></code>.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.repr.ReprPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.repr.</span></span><span class="sig-name descname"><span class="pre">ReprPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/repr.py#L17-L330"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.repr.ReprPrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.repr.ReprPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_sympyrepr'</span></em><a class="headerlink" href="#sympy.printing.repr.ReprPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.repr.ReprPrinter.emptyPrinter">
<span class="sig-name descname"><span class="pre">emptyPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/repr.py#L31-L47"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.repr.ReprPrinter.emptyPrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>The fallback printer.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.repr.ReprPrinter.reprify">
<span class="sig-name descname"><span class="pre">reprify</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sep</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/repr.py#L25-L29"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.repr.ReprPrinter.reprify" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints each item in <span class="math notranslate nohighlight">\(args\)</span> and joins them with <span class="math notranslate nohighlight">\(sep\)</span>.</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.repr.srepr">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.repr.</span></span><span class="sig-name descname"><span class="pre">srepr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm_cyclic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/repr.py#L332-L335"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.repr.srepr" title="Permalink to this definition">¶</a></dt>
<dd><p>return expr in repr form</p>
</dd></dl>

</section>
<section id="module-sympy.printing.str">
<span id="strprinter"></span><h2>StrPrinter<a class="headerlink" href="#module-sympy.printing.str" title="Permalink to this headline">¶</a></h2>
<p>This module generates readable representations of SymPy expressions.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.str.StrPrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.str.</span></span><span class="sig-name descname"><span class="pre">StrPrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/str.py#L19-L966"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.str.StrPrinter" title="Permalink to this definition">¶</a></dt>
<dd><dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.str.StrPrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_sympystr'</span></em><a class="headerlink" href="#sympy.printing.str.StrPrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.str.sstr">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.str.</span></span><span class="sig-name descname"><span class="pre">sstr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full_prec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'auto'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sympy_integers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">abbrev</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm_cyclic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/str.py#L969-L989"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.str.sstr" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the expression as a string.</p>
<p>For large expressions where speed is a concern, use the setting
order=’none’. If abbrev=True setting is used then units are printed in
abbreviated form.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">Eq</span><span class="p">,</span> <span class="n">sstr</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s1">&#39;a b&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">sstr</span><span class="p">(</span><span class="n">Eq</span><span class="p">(</span><span class="n">a</span> <span class="o">+</span> <span class="n">b</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">&#39;Eq(a + b, 0)&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.str.sstrrepr">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.str.</span></span><span class="sig-name descname"><span class="pre">sstrrepr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">order</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">full_prec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'auto'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sympy_integers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">abbrev</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perm_cyclic</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">min</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/str.py#L1003-L1016"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.str.sstrrepr" title="Permalink to this definition">¶</a></dt>
<dd><p>return expr in mixed str/repr form</p>
<p>i.e. strings are returned in repr form with quotes, and everything else
is returned in str form.</p>
<p>This function could be useful for hooking into sys.displayhook</p>
</dd></dl>

</section>
<section id="module-sympy.printing.tree">
<span id="tree-printing"></span><h2>Tree Printing<a class="headerlink" href="#module-sympy.printing.tree" title="Permalink to this headline">¶</a></h2>
<p>The functions in this module create a representation of an expression as a
tree.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.tree.pprint_nodes">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.tree.</span></span><span class="sig-name descname"><span class="pre">pprint_nodes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">subtrees</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/tree.py#L1-L33"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.tree.pprint_nodes" title="Permalink to this definition">¶</a></dt>
<dd><p>Prettyprints systems of nodes.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.tree</span> <span class="kn">import</span> <span class="n">pprint_nodes</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">pprint_nodes</span><span class="p">([</span><span class="s2">&quot;a&quot;</span><span class="p">,</span> <span class="s2">&quot;b1</span><span class="se">\n</span><span class="s2">b2&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">]))</span>
<span class="go">+-a</span>
<span class="go">+-b1</span>
<span class="go">| b2</span>
<span class="go">+-c</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.tree.print_node">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.tree.</span></span><span class="sig-name descname"><span class="pre">print_node</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">node</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assumptions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/tree.py#L36-L62"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.tree.print_node" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns information about the “node”.</p>
<p>This includes class name, string representation and assumptions.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>assumptions</strong> : bool, optional</p>
<blockquote>
<div><p>See the <code class="docutils literal notranslate"><span class="pre">assumptions</span></code> keyword in <code class="docutils literal notranslate"><span class="pre">tree</span></code></p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.tree.tree">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.tree.</span></span><span class="sig-name descname"><span class="pre">tree</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">node</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assumptions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/tree.py#L65-L93"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.tree.tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a tree representation of “node” as a string.</p>
<p>It uses print_node() together with pprint_nodes() on node.args recursively.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>asssumptions</strong> : bool, optional</p>
<blockquote>
<div><p>The flag to decide whether to print out all the assumption data
(such as <code class="docutils literal notranslate"><span class="pre">is_integer`,</span> <span class="pre">``is_real</span></code>) associated with the
expression or not.</p>
<p>Enabling the flag makes the result verbose, and the printed
result may not be determinisitic because of the randomness used
in backtracing the assumptions.</p>
</div></blockquote>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.printing.tree.print_tree" title="sympy.printing.tree.print_tree"><code class="xref py py-obj docutils literal notranslate"><span class="pre">print_tree</span></code></a></p>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.tree.print_tree">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.tree.</span></span><span class="sig-name descname"><span class="pre">print_tree</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">node</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assumptions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/tree.py#L96-L175"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.tree.print_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Prints a tree representation of “node”.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>asssumptions</strong> : bool, optional</p>
<blockquote>
<div><p>The flag to decide whether to print out all the assumption data
(such as <code class="docutils literal notranslate"><span class="pre">is_integer`,</span> <span class="pre">``is_real</span></code>) associated with the
expression or not.</p>
<p>Enabling the flag makes the result verbose, and the printed
result may not be determinisitic because of the randomness used
in backtracing the assumptions.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing</span> <span class="kn">import</span> <span class="n">print_tree</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">odd</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">even</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Printing with full assumptions information:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">print_tree</span><span class="p">(</span><span class="n">y</span><span class="o">**</span><span class="n">x</span><span class="p">)</span>
<span class="go">Pow: y**x</span>
<span class="go">+-Symbol: y</span>
<span class="go">| algebraic: True</span>
<span class="go">| commutative: True</span>
<span class="go">| complex: True</span>
<span class="go">| even: True</span>
<span class="go">| extended_real: True</span>
<span class="go">| finite: True</span>
<span class="go">| hermitian: True</span>
<span class="go">| imaginary: False</span>
<span class="go">| infinite: False</span>
<span class="go">| integer: True</span>
<span class="go">| irrational: False</span>
<span class="go">| noninteger: False</span>
<span class="go">| odd: False</span>
<span class="go">| rational: True</span>
<span class="go">| real: True</span>
<span class="go">| transcendental: False</span>
<span class="go">+-Symbol: x</span>
<span class="go">  algebraic: True</span>
<span class="go">  commutative: True</span>
<span class="go">  complex: True</span>
<span class="go">  even: False</span>
<span class="go">  extended_nonzero: True</span>
<span class="go">  extended_real: True</span>
<span class="go">  finite: True</span>
<span class="go">  hermitian: True</span>
<span class="go">  imaginary: False</span>
<span class="go">  infinite: False</span>
<span class="go">  integer: True</span>
<span class="go">  irrational: False</span>
<span class="go">  noninteger: False</span>
<span class="go">  nonzero: True</span>
<span class="go">  odd: True</span>
<span class="go">  rational: True</span>
<span class="go">  real: True</span>
<span class="go">  transcendental: False</span>
<span class="go">  zero: False</span>
</pre></div>
</div>
<p>Hiding the assumptions:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">print_tree</span><span class="p">(</span><span class="n">y</span><span class="o">**</span><span class="n">x</span><span class="p">,</span> <span class="n">assumptions</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="go">Pow: y**x</span>
<span class="go">+-Symbol: y</span>
<span class="go">+-Symbol: x</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#sympy.printing.tree.tree" title="sympy.printing.tree.tree"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tree</span></code></a></p>
</div>
</dd></dl>

</section>
<section id="preview">
<h2>Preview<a class="headerlink" href="#preview" title="Permalink to this headline">¶</a></h2>
<p>A useful function is <code class="docutils literal notranslate"><span class="pre">preview</span></code>:</p>
<span class="target" id="module-sympy.printing.preview"></span><dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.preview.preview">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.preview.</span></span><span class="sig-name descname"><span class="pre">preview</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">output</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'png'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">viewer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">euler</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">packages</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">outputbuffer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">preamble</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dvioptions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">outputTexFile</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">latex_settings</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/preview.py#L82-L333"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.preview.preview" title="Permalink to this definition">¶</a></dt>
<dd><p>View expression or LaTeX markup in PNG, DVI, PostScript or PDF form.</p>
<p>If the expr argument is an expression, it will be exported to LaTeX and
then compiled using the available TeX distribution.  The first argument,
‘expr’, may also be a LaTeX string.  The function will then run the
appropriate viewer for the given output format or use the user defined
one. By default png output is generated.</p>
<p>By default pretty Euler fonts are used for typesetting (they were used to
typeset the well known “Concrete Mathematics” book). For that to work, you
need the ‘eulervm.sty’ LaTeX style (in Debian/Ubuntu, install the
texlive-fonts-extra package). If you prefer default AMS fonts or your
system lacks ‘eulervm’ LaTeX package then unset the ‘euler’ keyword
argument.</p>
<p>To use viewer auto-detection, lets say for ‘png’ output, issue</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">symbols</span><span class="p">,</span> <span class="n">preview</span><span class="p">,</span> <span class="n">Symbol</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">symbols</span><span class="p">(</span><span class="s2">&quot;x,y&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;png&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>This will choose ‘pyglet’ by default. To select a different one, do</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;png&#39;</span><span class="p">,</span> <span class="n">viewer</span><span class="o">=</span><span class="s1">&#39;gimp&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The ‘png’ format is considered special. For all other formats the rules
are slightly different. As an example we will take ‘dvi’ output format. If
you would run</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;dvi&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>then ‘view’ will look for available ‘dvi’ viewers on your system
(predefined in the function, so it will try evince, first, then kdvi and
xdvi). If nothing is found you will need to set the viewer explicitly.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;dvi&#39;</span><span class="p">,</span> <span class="n">viewer</span><span class="o">=</span><span class="s1">&#39;superior-dvi-viewer&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>This will skip auto-detection and will run user specified
‘superior-dvi-viewer’. If ‘view’ fails to find it on your system it will
gracefully raise an exception.</p>
<p>You may also enter ‘file’ for the viewer argument. Doing so will cause
this function to return a file object in read-only mode, if ‘filename’
is unset. However, if it was set, then ‘preview’ writes the genereted
file to this filename instead.</p>
<p>There is also support for writing to a BytesIO like object, which needs
to be passed to the ‘outputbuffer’ argument.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="n">BytesIO</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">obj</span> <span class="o">=</span> <span class="n">BytesIO</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;png&#39;</span><span class="p">,</span> <span class="n">viewer</span><span class="o">=</span><span class="s1">&#39;BytesIO&#39;</span><span class="p">,</span>
<span class="gp">... </span>        <span class="n">outputbuffer</span><span class="o">=</span><span class="n">obj</span><span class="p">)</span>
</pre></div>
</div>
<p>The LaTeX preamble can be customized by setting the ‘preamble’ keyword
argument. This can be used, e.g., to set a different font size, use a
custom documentclass or import certain set of LaTeX packages.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preamble</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">documentclass[10pt]</span><span class="si">{article}</span><span class="se">\n</span><span class="s2">&quot;</span> \
<span class="gp">... </span>           <span class="s2">&quot;</span><span class="se">\\</span><span class="s2">usepackage{amsmath,amsfonts}</span><span class="se">\\</span><span class="s2">begin</span><span class="si">{document}</span><span class="s2">&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">output</span><span class="o">=</span><span class="s1">&#39;png&#39;</span><span class="p">,</span> <span class="n">preamble</span><span class="o">=</span><span class="n">preamble</span><span class="p">)</span>
</pre></div>
</div>
<p>If the value of ‘output’ is different from ‘dvi’ then command line
options can be set (‘dvioptions’ argument) for the execution of the
‘dvi’+output conversion tool. These options have to be in the form of a
list of strings (see subprocess.Popen).</p>
<p>Additional keyword args will be passed to the latex call, e.g., the
symbol_names flag.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">phidd</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;phidd&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">phidd</span><span class="p">,</span> <span class="n">symbol_names</span><span class="o">=</span><span class="p">{</span><span class="n">phidd</span><span class="p">:</span><span class="sa">r</span><span class="s1">&#39;\ddot{\varphi}&#39;</span><span class="p">})</span>
</pre></div>
</div>
<p>For post-processing the generated TeX File can be written to a file by
passing the desired filename to the ‘outputTexFile’ keyword
argument. To write the TeX code to a file named
“sample.tex” and run the default png viewer to display the resulting
bitmap, do</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">preview</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="n">outputTexFile</span><span class="o">=</span><span class="s2">&quot;sample.tex&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</section>
<section id="module-sympy.printing.conventions">
<span id="implementation-helper-classes-functions"></span><h2>Implementation - Helper Classes/Functions<a class="headerlink" href="#module-sympy.printing.conventions" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.conventions.split_super_sub">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.conventions.</span></span><span class="sig-name descname"><span class="pre">split_super_sub</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">text</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/conventions.py#L13-L70"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.conventions.split_super_sub" title="Permalink to this definition">¶</a></dt>
<dd><p>Split a symbol name into a name, superscripts and subscripts</p>
<p>The first part of the symbol name is considered to be its actual
‘name’, followed by super- and subscripts. Each superscript is
preceded with a “^” character or by “__”. Each subscript is preceded
by a “_” character.  The three return values are the actual name, a
list with superscripts and a list with subscripts.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.conventions</span> <span class="kn">import</span> <span class="n">split_super_sub</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">split_super_sub</span><span class="p">(</span><span class="s1">&#39;a_x^1&#39;</span><span class="p">)</span>
<span class="go">(&#39;a&#39;, [&#39;1&#39;], [&#39;x&#39;])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">split_super_sub</span><span class="p">(</span><span class="s1">&#39;var_sub1__sup_sub2&#39;</span><span class="p">)</span>
<span class="go">(&#39;var&#39;, [&#39;sup&#39;], [&#39;sub1&#39;, &#39;sub2&#39;])</span>
</pre></div>
</div>
</dd></dl>

<section id="module-sympy.printing.codeprinter">
<span id="codeprinter"></span><h3>CodePrinter<a class="headerlink" href="#module-sympy.printing.codeprinter" title="Permalink to this headline">¶</a></h3>
<p>This class is a base class for other classes that implement code-printing
functionality, and additionally lists a number of functions that cannot be
easily translated to C or Fortran.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.codeprinter.CodePrinter">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.codeprinter.</span></span><span class="sig-name descname"><span class="pre">CodePrinter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">settings</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L35-L539"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.codeprinter.CodePrinter" title="Permalink to this definition">¶</a></dt>
<dd><p>The base class for code-printing subclasses.</p>
<dl class="py attribute">
<dt class="sig sig-object py" id="sympy.printing.codeprinter.CodePrinter.printmethod">
<span class="sig-name descname"><span class="pre">printmethod</span></span><em class="property"><span class="pre">:</span> <span class="pre">str</span></em><em class="property"> <span class="pre">=</span> <span class="pre">'_sympystr'</span></em><a class="headerlink" href="#sympy.printing.codeprinter.CodePrinter.printmethod" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.codeprinter.CodePrinter.doprint">
<span class="sig-name descname"><span class="pre">doprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">assign_to</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L70-L131"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.codeprinter.CodePrinter.doprint" title="Permalink to this definition">¶</a></dt>
<dd><p>Print the expression as code.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expression</p>
<blockquote>
<div><p>The expression to be printed.</p>
</div></blockquote>
<p><strong>assign_to</strong> : Symbol, string, MatrixSymbol, list of strings or Symbols (optional)</p>
<blockquote>
<div><p>If provided, the printed code will set the expression to a variable or multiple variables
with the name or names given in <code class="docutils literal notranslate"><span class="pre">assign_to</span></code>.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py exception">
<dt class="sig sig-object py" id="sympy.printing.codeprinter.AssignmentError">
<em class="property"><span class="pre">exception</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.codeprinter.</span></span><span class="sig-name descname"><span class="pre">AssignmentError</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/codeprinter.py#L28-L32"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.codeprinter.AssignmentError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised if an assignment variable for a loop is missing.</p>
</dd></dl>

</section>
<section id="module-sympy.printing.precedence">
<span id="precedence"></span><h3>Precedence<a class="headerlink" href="#module-sympy.printing.precedence" title="Permalink to this headline">¶</a></h3>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.precedence.PRECEDENCE">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.precedence.</span></span><span class="sig-name descname"><span class="pre">PRECEDENCE</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Add':</span> <span class="pre">40,</span> <span class="pre">'And':</span> <span class="pre">30,</span> <span class="pre">'Atom':</span> <span class="pre">1000,</span> <span class="pre">'BitwiseAnd':</span> <span class="pre">38,</span> <span class="pre">'BitwiseOr':</span> <span class="pre">36,</span> <span class="pre">'BitwiseXor':</span> <span class="pre">37,</span> <span class="pre">'Func':</span> <span class="pre">70,</span> <span class="pre">'Lambda':</span> <span class="pre">1,</span> <span class="pre">'Mul':</span> <span class="pre">50,</span> <span class="pre">'Not':</span> <span class="pre">100,</span> <span class="pre">'Or':</span> <span class="pre">20,</span> <span class="pre">'Pow':</span> <span class="pre">60,</span> <span class="pre">'Relational':</span> <span class="pre">35,</span> <span class="pre">'Xor':</span> <span class="pre">10}</span></em><a class="headerlink" href="#sympy.printing.precedence.PRECEDENCE" title="Permalink to this definition">¶</a></dt>
<dd><p>Default precedence values for some basic types.</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.precedence.PRECEDENCE_VALUES">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.precedence.</span></span><span class="sig-name descname"><span class="pre">PRECEDENCE_VALUES</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Add':</span> <span class="pre">40,</span> <span class="pre">'And':</span> <span class="pre">30,</span> <span class="pre">'Equality':</span> <span class="pre">50,</span> <span class="pre">'Equivalent':</span> <span class="pre">10,</span> <span class="pre">'Function':</span> <span class="pre">70,</span> <span class="pre">'HadamardPower':</span> <span class="pre">60,</span> <span class="pre">'HadamardProduct':</span> <span class="pre">50,</span> <span class="pre">'Implies':</span> <span class="pre">10,</span> <span class="pre">'KroneckerProduct':</span> <span class="pre">50,</span> <span class="pre">'MatAdd':</span> <span class="pre">40,</span> <span class="pre">'MatPow':</span> <span class="pre">60,</span> <span class="pre">'MatrixSolve':</span> <span class="pre">50,</span> <span class="pre">'NegativeInfinity':</span> <span class="pre">40,</span> <span class="pre">'Not':</span> <span class="pre">100,</span> <span class="pre">'Or':</span> <span class="pre">20,</span> <span class="pre">'Pow':</span> <span class="pre">60,</span> <span class="pre">'Relational':</span> <span class="pre">35,</span> <span class="pre">'Sub':</span> <span class="pre">40,</span> <span class="pre">'TensAdd':</span> <span class="pre">40,</span> <span class="pre">'TensMul':</span> <span class="pre">50,</span> <span class="pre">'Unequality':</span> <span class="pre">50,</span> <span class="pre">'Xor':</span> <span class="pre">10}</span></em><a class="headerlink" href="#sympy.printing.precedence.PRECEDENCE_VALUES" title="Permalink to this definition">¶</a></dt>
<dd><p>A dictionary assigning precedence values to certain classes. These values
are treated like they were inherited, so not every single class has to be
named here.</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.precedence.PRECEDENCE_FUNCTIONS">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.precedence.</span></span><span class="sig-name descname"><span class="pre">PRECEDENCE_FUNCTIONS</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Float':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_Float&gt;,</span> <span class="pre">'FracElement':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_FracElement&gt;,</span> <span class="pre">'Integer':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_Integer&gt;,</span> <span class="pre">'Mul':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_Mul&gt;,</span> <span class="pre">'PolyElement':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_PolyElement&gt;,</span> <span class="pre">'Rational':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_Rational&gt;,</span> <span class="pre">'UnevaluatedExpr':</span> <span class="pre">&lt;function</span> <span class="pre">precedence_UnevaluatedExpr&gt;}</span></em><a class="headerlink" href="#sympy.printing.precedence.PRECEDENCE_FUNCTIONS" title="Permalink to this definition">¶</a></dt>
<dd><p>Sometimes it’s not enough to assign a fixed precedence value to a
class. Then a function can be inserted in this dictionary that takes an
instance of this class as argument and returns the appropriate precedence
value.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.precedence.precedence">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.precedence.</span></span><span class="sig-name descname"><span class="pre">precedence</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">item</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/precedence.py#L118-L135"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.precedence.precedence" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the precedence of a given object.</p>
<p>This is the precedence for StrPrinter.</p>
</dd></dl>

</section>
</section>
<section id="module-sympy.printing.pretty.pretty_symbology">
<span id="pretty-printing-implementation-helpers"></span><h2>Pretty-Printing Implementation Helpers<a class="headerlink" href="#module-sympy.printing.pretty.pretty_symbology" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.U">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">U</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L10-L21"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.U" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a unicode character by name or, None if not found.</p>
<p>This exists because older versions of python use older unicode databases.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.pretty_use_unicode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">pretty_use_unicode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">flag</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L41-L55"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.pretty_use_unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>Set whether pretty-printer should use unicode by default</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.pretty_try_use_unicode">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">pretty_try_use_unicode</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L58-L86"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.pretty_try_use_unicode" title="Permalink to this definition">¶</a></dt>
<dd><p>See if unicode output is available and leverage it if possible</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.xstr">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">xstr</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L89-L94"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.xstr" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The following two functions return the Unicode version of the inputted Greek
letter.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.g">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">g</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">l</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L97-L97"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.g" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.G">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">G</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">l</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L98-L98"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.G" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.greek_letters">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">greek_letters</span></span><em class="property"> <span class="pre">=</span> <span class="pre">['alpha',</span> <span class="pre">'beta',</span> <span class="pre">'gamma',</span> <span class="pre">'delta',</span> <span class="pre">'epsilon',</span> <span class="pre">'zeta',</span> <span class="pre">'eta',</span> <span class="pre">'theta',</span> <span class="pre">'iota',</span> <span class="pre">'kappa',</span> <span class="pre">'lamda',</span> <span class="pre">'mu',</span> <span class="pre">'nu',</span> <span class="pre">'xi',</span> <span class="pre">'omicron',</span> <span class="pre">'pi',</span> <span class="pre">'rho',</span> <span class="pre">'sigma',</span> <span class="pre">'tau',</span> <span class="pre">'upsilon',</span> <span class="pre">'phi',</span> <span class="pre">'chi',</span> <span class="pre">'psi',</span> <span class="pre">'omega']</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.greek_letters" title="Permalink to this definition">¶</a></dt>
<dd><p>Built-in mutable sequence.</p>
<p>If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.digit_2txt">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">digit_2txt</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'0':</span> <span class="pre">'ZERO',</span> <span class="pre">'1':</span> <span class="pre">'ONE',</span> <span class="pre">'2':</span> <span class="pre">'TWO',</span> <span class="pre">'3':</span> <span class="pre">'THREE',</span> <span class="pre">'4':</span> <span class="pre">'FOUR',</span> <span class="pre">'5':</span> <span class="pre">'FIVE',</span> <span class="pre">'6':</span> <span class="pre">'SIX',</span> <span class="pre">'7':</span> <span class="pre">'SEVEN',</span> <span class="pre">'8':</span> <span class="pre">'EIGHT',</span> <span class="pre">'9':</span> <span class="pre">'NINE'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.digit_2txt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.symb_2txt">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">symb_2txt</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'(':</span> <span class="pre">'LEFT</span> <span class="pre">PARENTHESIS',</span> <span class="pre">')':</span> <span class="pre">'RIGHT</span> <span class="pre">PARENTHESIS',</span> <span class="pre">'+':</span> <span class="pre">'PLUS</span> <span class="pre">SIGN',</span> <span class="pre">'-':</span> <span class="pre">'MINUS',</span> <span class="pre">'=':</span> <span class="pre">'EQUALS</span> <span class="pre">SIGN',</span> <span class="pre">'[':</span> <span class="pre">'LEFT</span> <span class="pre">SQUARE</span> <span class="pre">BRACKET',</span> <span class="pre">']':</span> <span class="pre">'RIGHT</span> <span class="pre">SQUARE</span> <span class="pre">BRACKET',</span> <span class="pre">'int':</span> <span class="pre">'INTEGRAL',</span> <span class="pre">'sum':</span> <span class="pre">'SUMMATION',</span> <span class="pre">'{':</span> <span class="pre">'LEFT</span> <span class="pre">CURLY</span> <span class="pre">BRACKET',</span> <span class="pre">'{}':</span> <span class="pre">'CURLY</span> <span class="pre">BRACKET',</span> <span class="pre">'}':</span> <span class="pre">'RIGHT</span> <span class="pre">CURLY</span> <span class="pre">BRACKET'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.symb_2txt" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The following functions return the Unicode subscript/superscript version of
the character.</p>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.sub">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">sub</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'(':</span> <span class="pre">'₍',</span> <span class="pre">')':</span> <span class="pre">'₎',</span> <span class="pre">'+':</span> <span class="pre">'₊',</span> <span class="pre">'-':</span> <span class="pre">'₋',</span> <span class="pre">'0':</span> <span class="pre">'₀',</span> <span class="pre">'1':</span> <span class="pre">'₁',</span> <span class="pre">'2':</span> <span class="pre">'₂',</span> <span class="pre">'3':</span> <span class="pre">'₃',</span> <span class="pre">'4':</span> <span class="pre">'₄',</span> <span class="pre">'5':</span> <span class="pre">'₅',</span> <span class="pre">'6':</span> <span class="pre">'₆',</span> <span class="pre">'7':</span> <span class="pre">'₇',</span> <span class="pre">'8':</span> <span class="pre">'₈',</span> <span class="pre">'9':</span> <span class="pre">'₉',</span> <span class="pre">'=':</span> <span class="pre">'₌',</span> <span class="pre">'a':</span> <span class="pre">'ₐ',</span> <span class="pre">'beta':</span> <span class="pre">'ᵦ',</span> <span class="pre">'chi':</span> <span class="pre">'ᵪ',</span> <span class="pre">'e':</span> <span class="pre">'ₑ',</span> <span class="pre">'gamma':</span> <span class="pre">'ᵧ',</span> <span class="pre">'h':</span> <span class="pre">'ₕ',</span> <span class="pre">'i':</span> <span class="pre">'ᵢ',</span> <span class="pre">'k':</span> <span class="pre">'ₖ',</span> <span class="pre">'l':</span> <span class="pre">'ₗ',</span> <span class="pre">'m':</span> <span class="pre">'ₘ',</span> <span class="pre">'n':</span> <span class="pre">'ₙ',</span> <span class="pre">'o':</span> <span class="pre">'ₒ',</span> <span class="pre">'p':</span> <span class="pre">'ₚ',</span> <span class="pre">'phi':</span> <span class="pre">'ᵩ',</span> <span class="pre">'r':</span> <span class="pre">'ᵣ',</span> <span class="pre">'rho':</span> <span class="pre">'ᵨ',</span> <span class="pre">'s':</span> <span class="pre">'ₛ',</span> <span class="pre">'t':</span> <span class="pre">'ₜ',</span> <span class="pre">'u':</span> <span class="pre">'ᵤ',</span> <span class="pre">'v':</span> <span class="pre">'ᵥ',</span> <span class="pre">'x':</span> <span class="pre">'ₓ'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.sub" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.sup">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">sup</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'(':</span> <span class="pre">'⁽',</span> <span class="pre">')':</span> <span class="pre">'⁾',</span> <span class="pre">'+':</span> <span class="pre">'⁺',</span> <span class="pre">'-':</span> <span class="pre">'⁻',</span> <span class="pre">'0':</span> <span class="pre">'⁰',</span> <span class="pre">'1':</span> <span class="pre">'¹',</span> <span class="pre">'2':</span> <span class="pre">'²',</span> <span class="pre">'3':</span> <span class="pre">'³',</span> <span class="pre">'4':</span> <span class="pre">'⁴',</span> <span class="pre">'5':</span> <span class="pre">'⁵',</span> <span class="pre">'6':</span> <span class="pre">'⁶',</span> <span class="pre">'7':</span> <span class="pre">'⁷',</span> <span class="pre">'8':</span> <span class="pre">'⁸',</span> <span class="pre">'9':</span> <span class="pre">'⁹',</span> <span class="pre">'=':</span> <span class="pre">'⁼',</span> <span class="pre">'i':</span> <span class="pre">'ⁱ',</span> <span class="pre">'n':</span> <span class="pre">'ⁿ'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.sup" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The following functions return Unicode vertical objects.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.xobj">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">xobj</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symb</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">length</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L313-L378"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.xobj" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct spatial object of given length.</p>
<p>return: [] of equal-length strings</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.vobj">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">vobj</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symb</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">height</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L381-L386"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.vobj" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct vertical object of a given height</p>
<p>see: xobj</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.hobj">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">hobj</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symb</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">width</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L389-L394"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.hobj" title="Permalink to this definition">¶</a></dt>
<dd><p>Construct horizontal object of a given width</p>
<p>see: xobj</p>
</dd></dl>

<p>The following constants are for rendering roots and fractions.</p>
<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.root">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">root</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{2:</span> <span class="pre">'√',</span> <span class="pre">3:</span> <span class="pre">'∛',</span> <span class="pre">4:</span> <span class="pre">'∜'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.root" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.VF">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">VF</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">txt</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L406-L406"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.VF" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.frac">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">frac</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{(1,</span> <span class="pre">2):</span> <span class="pre">'½',</span> <span class="pre">(1,</span> <span class="pre">3):</span> <span class="pre">'⅓',</span> <span class="pre">(1,</span> <span class="pre">4):</span> <span class="pre">'¼',</span> <span class="pre">(1,</span> <span class="pre">5):</span> <span class="pre">'⅕',</span> <span class="pre">(1,</span> <span class="pre">6):</span> <span class="pre">'⅙',</span> <span class="pre">(1,</span> <span class="pre">8):</span> <span class="pre">'⅛',</span> <span class="pre">(2,</span> <span class="pre">3):</span> <span class="pre">'⅔',</span> <span class="pre">(2,</span> <span class="pre">5):</span> <span class="pre">'⅖',</span> <span class="pre">(3,</span> <span class="pre">4):</span> <span class="pre">'¾',</span> <span class="pre">(3,</span> <span class="pre">5):</span> <span class="pre">'⅗',</span> <span class="pre">(3,</span> <span class="pre">8):</span> <span class="pre">'⅜',</span> <span class="pre">(4,</span> <span class="pre">5):</span> <span class="pre">'⅘',</span> <span class="pre">(5,</span> <span class="pre">6):</span> <span class="pre">'⅚',</span> <span class="pre">(5,</span> <span class="pre">8):</span> <span class="pre">'⅝',</span> <span class="pre">(7,</span> <span class="pre">8):</span> <span class="pre">'⅞'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.frac" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<p>The following constants/functions are for rendering atoms and symbols.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.xsym">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">xsym</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sym</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L456-L463"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.xsym" title="Permalink to this definition">¶</a></dt>
<dd><p>get symbology for a ‘character’</p>
</dd></dl>

<dl class="py data">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.atoms_table">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">atoms_table</span></span><em class="property"> <span class="pre">=</span> <span class="pre">{'Complexes':</span> <span class="pre">'ℂ',</span> <span class="pre">'EmptySequence':</span> <span class="pre">'EmptySequence',</span> <span class="pre">'EmptySet':</span> <span class="pre">'∅',</span> <span class="pre">'Exp1':</span> <span class="pre">'ℯ',</span> <span class="pre">'ImaginaryUnit':</span> <span class="pre">'ⅈ',</span> <span class="pre">'Infinity':</span> <span class="pre">'∞',</span> <span class="pre">'Integers':</span> <span class="pre">'ℤ',</span> <span class="pre">'Intersection':</span> <span class="pre">'∩',</span> <span class="pre">'Modifier</span> <span class="pre">Letter</span> <span class="pre">Low</span> <span class="pre">Ring':</span> <span class="pre">'˳',</span> <span class="pre">'Naturals':</span> <span class="pre">'ℕ',</span> <span class="pre">'Naturals0':</span> <span class="pre">'ℕ₀',</span> <span class="pre">'NegativeInfinity':</span> <span class="pre">'-∞',</span> <span class="pre">'Pi':</span> <span class="pre">'π',</span> <span class="pre">'Rationals':</span> <span class="pre">'ℚ',</span> <span class="pre">'Reals':</span> <span class="pre">'ℝ',</span> <span class="pre">'Ring':</span> <span class="pre">'∘',</span> <span class="pre">'SymmetricDifference':</span> <span class="pre">'∆',</span> <span class="pre">'Union':</span> <span class="pre">'∪'}</span></em><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.atoms_table" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.pretty_atom">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">pretty_atom</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">atom_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">default</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">printer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L495-L506"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.pretty_atom" title="Permalink to this definition">¶</a></dt>
<dd><p>return pretty representation of an atom</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.pretty_symbol">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">pretty_symbol</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">symb_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">bold_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L509-L567"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.pretty_symbol" title="Permalink to this definition">¶</a></dt>
<dd><p>return pretty representation of a symbol</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.pretty.pretty_symbology.annotated">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.pretty_symbology.</span></span><span class="sig-name descname"><span class="pre">annotated</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">letter</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/pretty_symbology.py#L570-L595"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.pretty_symbology.annotated" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a stylised drawing of the letter <code class="docutils literal notranslate"><span class="pre">letter</span></code>, together with
information on how to put annotations (super- and subscripts to the
left and to the right) on it.</p>
<p>See pretty.py functions _print_meijerg, _print_hyper on how to use this
information.</p>
</dd></dl>

<span class="target" id="module-sympy.printing.pretty.stringpict"></span><p>Prettyprinter by Jurjen Bos.
(I hate spammers: mail me at pietjepuk314 at the reverse of ku.oc.oohay).
All objects have a method that create a “stringPict”,
that can be used in the str method for pretty printing.</p>
<dl class="simple">
<dt>Updates by Jason Gedge (email &lt;my last name&gt; at cs mun ca)</dt><dd><ul class="simple">
<li><p>terminal_string() method</p></li>
<li><p>minor fixes and changes (mostly to prettyForm)</p></li>
</ul>
</dd>
<dt>TODO:</dt><dd><ul class="simple">
<li><p>Allow left/center/right alignment options for above/below and
top/center/bottom alignment options for left/right</p></li>
</ul>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.stringpict.</span></span><span class="sig-name descname"><span class="pre">stringPict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">baseline</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L18-L352"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict" title="Permalink to this definition">¶</a></dt>
<dd><p>An ASCII picture.
The pictures are represented as a list of equal length strings.</p>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.above">
<span class="sig-name descname"><span class="pre">above</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L166-L173"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.above" title="Permalink to this definition">¶</a></dt>
<dd><p>Put pictures above this picture.
Returns string, baseline arguments for stringPict.
Baseline is baseline of bottom picture.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.below">
<span class="sig-name descname"><span class="pre">below</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L147-L164"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.below" title="Permalink to this definition">¶</a></dt>
<dd><p>Put pictures under this picture.
Returns string, baseline arguments for stringPict.
Baseline is baseline of top picture</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.pretty.stringpict</span> <span class="kn">import</span> <span class="n">stringPict</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">stringPict</span><span class="p">(</span><span class="s2">&quot;x+3&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">below</span><span class="p">(</span>
<span class="gp">... </span>      <span class="n">stringPict</span><span class="o">.</span><span class="n">LINE</span><span class="p">,</span> <span class="s1">&#39;3&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> 
<span class="go">x+3</span>
<span class="go">---</span>
<span class="go"> 3</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.height">
<span class="sig-name descname"><span class="pre">height</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L45-L47"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.height" title="Permalink to this definition">¶</a></dt>
<dd><p>The height of the picture in characters.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.left">
<span class="sig-name descname"><span class="pre">left</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L102-L106"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.left" title="Permalink to this definition">¶</a></dt>
<dd><p>Put pictures (left to right) at left.
Returns string, baseline arguments for stringPict.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.leftslash">
<span class="sig-name descname"><span class="pre">leftslash</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L201-L212"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.leftslash" title="Permalink to this definition">¶</a></dt>
<dd><p>Precede object by a slash of the proper size.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.next">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">next</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L53-L83"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.next" title="Permalink to this definition">¶</a></dt>
<dd><p>Put a string of stringPicts next to each other.
Returns string, baseline arguments for stringPict.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.parens">
<span class="sig-name descname"><span class="pre">parens</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">left</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'('</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">right</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">')'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ifascii_nougly</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L175-L199"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.parens" title="Permalink to this definition">¶</a></dt>
<dd><p>Put parentheses around self.
Returns string, baseline arguments for stringPict.</p>
<p>left or right can be None or empty string which means ‘no paren from
that side’</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.render">
<span class="sig-name descname"><span class="pre">render</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L248-L296"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.render" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the string form of self.</p>
<p>Unless the argument line_break is set to False, it will
break the expression in a form that can be printed
on the terminal without being broken up.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.right">
<span class="sig-name descname"><span class="pre">right</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L85-L100"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.right" title="Permalink to this definition">¶</a></dt>
<dd><p>Put pictures next to this one.
Returns string, baseline arguments for stringPict.
(Multiline) strings are allowed, and are given a baseline of 0.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.pretty.stringpict</span> <span class="kn">import</span> <span class="n">stringPict</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">stringPict</span><span class="p">(</span><span class="s2">&quot;10&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="s2">&quot; + &quot;</span><span class="p">,</span><span class="n">stringPict</span><span class="p">(</span><span class="s2">&quot;1</span><span class="se">\r</span><span class="s2">-</span><span class="se">\r</span><span class="s2">2&quot;</span><span class="p">,</span><span class="mi">1</span><span class="p">))[</span><span class="mi">0</span><span class="p">])</span>
<span class="go">     1</span>
<span class="go">10 + -</span>
<span class="go">     2</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.root">
<span class="sig-name descname"><span class="pre">root</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L214-L246"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.root" title="Permalink to this definition">¶</a></dt>
<dd><p>Produce a nice root symbol.
Produces ugly results for big n inserts.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.stack">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">stack</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L108-L145"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.stack" title="Permalink to this definition">¶</a></dt>
<dd><p>Put pictures on top of each other,
from top to bottom.
Returns string, baseline arguments for stringPict.
The baseline is the baseline of the second picture.
Everything is centered.
Baseline is the baseline of the second picture.
Strings are allowed.
The special value stringPict.LINE is a row of ‘-’ extended to the width.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.terminal_width">
<span class="sig-name descname"><span class="pre">terminal_width</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L298-L330"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.terminal_width" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the terminal width if possible, otherwise return 0.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.stringPict.width">
<span class="sig-name descname"><span class="pre">width</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L49-L51"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.stringPict.width" title="Permalink to this definition">¶</a></dt>
<dd><p>The width of the picture in characters.</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.prettyForm">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.printing.pretty.stringpict.</span></span><span class="sig-name descname"><span class="pre">prettyForm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">baseline</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">binding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unicode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L355-L529"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.prettyForm" title="Permalink to this definition">¶</a></dt>
<dd><p>Extension of the stringPict class that knows about basic math applications,
optimizing double minus signs.</p>
<p>“Binding” is interpreted as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>ATOM this is an atom: never needs to be parenthesized
FUNC this is a function application: parenthesize if added (?)
DIV  this is a division: make wider division if divided
POW  this is a power: only parenthesize if exponent
MUL  this is a multiplication: parenthesize if powered
ADD  this is an addition: parenthesize if multiplied or powered
NEG  this is a negative number: optimize if added, parenthesize if
     multiplied or powered
OPEN this is an open object: parenthesize if added, multiplied, or
     powered (example: Piecewise)
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.printing.pretty.stringpict.prettyForm.apply">
<em class="property"><span class="pre">static</span> </em><span class="sig-name descname"><span class="pre">apply</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/pretty/stringpict.py#L511-L529"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.pretty.stringpict.prettyForm.apply" title="Permalink to this definition">¶</a></dt>
<dd><p>Functions of one or more variables.</p>
</dd></dl>

</dd></dl>

</section>
<section id="dotprint">
<h2>dotprint<a class="headerlink" href="#dotprint" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.printing.dot.dotprint">
<span class="sig-prename descclassname"><span class="pre">sympy.printing.dot.</span></span><span class="sig-name descname"><span class="pre">dotprint</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">expr</span></em>, <em class="sig-param"><span class="pre">styles=((&lt;class</span> <span class="pre">'sympy.core.basic.Basic'&gt;</span></em>, <em class="sig-param"><span class="pre">{'color':</span> <span class="pre">'blue'</span></em>, <em class="sig-param"><span class="pre">'shape':</span> <span class="pre">'ellipse'})</span></em>, <em class="sig-param"><span class="pre">(&lt;class</span> <span class="pre">'sympy.core.expr.Expr'&gt;</span></em>, <em class="sig-param"><span class="pre">{'color':</span> <span class="pre">'black'}))</span></em>, <em class="sig-param"><span class="pre">atom=&lt;function</span> <span class="pre">&lt;lambda&gt;&gt;</span></em>, <em class="sig-param"><span class="pre">maxdepth=None</span></em>, <em class="sig-param"><span class="pre">repeat=True</span></em>, <em class="sig-param"><span class="pre">labelfunc=&lt;class</span> <span class="pre">'str'&gt;</span></em>, <em class="sig-param"><span class="pre">**kwargs</span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/printing/dot.py#L186-L294"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.printing.dot.dotprint" title="Permalink to this definition">¶</a></dt>
<dd><p>DOT description of a SymPy expression tree</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>styles</strong> : list of lists composed of (Class, mapping), optional</p>
<blockquote>
<div><p>Styles for different classes.</p>
<p>The default is</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">(</span>
    <span class="p">(</span><span class="n">Basic</span><span class="p">,</span> <span class="p">{</span><span class="s1">&#39;color&#39;</span><span class="p">:</span> <span class="s1">&#39;blue&#39;</span><span class="p">,</span> <span class="s1">&#39;shape&#39;</span><span class="p">:</span> <span class="s1">&#39;ellipse&#39;</span><span class="p">}),</span>
    <span class="p">(</span><span class="n">Expr</span><span class="p">,</span>  <span class="p">{</span><span class="s1">&#39;color&#39;</span><span class="p">:</span> <span class="s1">&#39;black&#39;</span><span class="p">})</span>
<span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>atom</strong> : function, optional</p>
<blockquote>
<div><p>Function used to determine if an arg is an atom.</p>
<p>A good choice is <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">not</span> <span class="pre">x.args</span></code>.</p>
<p>The default is <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">not</span> <span class="pre">isinstance(x,</span> <span class="pre">Basic)</span></code>.</p>
</div></blockquote>
<p><strong>maxdepth</strong> : integer, optional</p>
<blockquote>
<div><p>The maximum depth.</p>
<p>The default is <code class="docutils literal notranslate"><span class="pre">None</span></code>, meaning no limit.</p>
</div></blockquote>
<p><strong>repeat</strong> : boolean, optional</p>
<blockquote>
<div><p>Whether to use different nodes for common subexpressions.</p>
<p>The default is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p>
<p>For example, for <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">x*y</span></code> with <code class="docutils literal notranslate"><span class="pre">repeat=True</span></code>, it will have
two nodes for <code class="docutils literal notranslate"><span class="pre">x</span></code>; with <code class="docutils literal notranslate"><span class="pre">repeat=False</span></code>, it will have one
node.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Even if a node appears twice in the same object like <code class="docutils literal notranslate"><span class="pre">x</span></code> in
<code class="docutils literal notranslate"><span class="pre">Pow(x,</span> <span class="pre">x)</span></code>, it will still only appear once.
Hence, with <code class="docutils literal notranslate"><span class="pre">repeat=False</span></code>, the number of arrows out of an
object might not equal the number of args it has.</p>
</div>
</div></blockquote>
<p><strong>labelfunc</strong> : function, optional</p>
<blockquote>
<div><p>A function to create a label for a given leaf node.</p>
<p>The default is <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
<p>Another good option is <code class="docutils literal notranslate"><span class="pre">srepr</span></code>.</p>
<p>For example with <code class="docutils literal notranslate"><span class="pre">str</span></code>, the leaf nodes of <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">1</span></code> are labeled,
<code class="docutils literal notranslate"><span class="pre">x</span></code> and <code class="docutils literal notranslate"><span class="pre">1</span></code>.  With <code class="docutils literal notranslate"><span class="pre">srepr</span></code>, they are labeled <code class="docutils literal notranslate"><span class="pre">Symbol('x')</span></code>
and <code class="docutils literal notranslate"><span class="pre">Integer(1)</span></code>.</p>
</div></blockquote>
<p><strong>**kwargs</strong> : optional</p>
<blockquote>
<div><p>Additional keyword arguments are included as styles for the graph.</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.printing.dot</span> <span class="kn">import</span> <span class="n">dotprint</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dotprint</span><span class="p">(</span><span class="n">x</span><span class="o">+</span><span class="mi">2</span><span class="p">))</span> 
<span class="go">digraph{</span>

<span class="go"># Graph style</span>
<span class="go">&quot;ordering&quot;=&quot;out&quot;</span>
<span class="go">&quot;rankdir&quot;=&quot;TD&quot;</span>

<span class="go">#########</span>
<span class="go"># Nodes #</span>
<span class="go">#########</span>

<span class="go">&quot;Add(Integer(2), Symbol(&#39;x&#39;))_()&quot; [&quot;color&quot;=&quot;black&quot;, &quot;label&quot;=&quot;Add&quot;, &quot;shape&quot;=&quot;ellipse&quot;];</span>
<span class="go">&quot;Integer(2)_(0,)&quot; [&quot;color&quot;=&quot;black&quot;, &quot;label&quot;=&quot;2&quot;, &quot;shape&quot;=&quot;ellipse&quot;];</span>
<span class="go">&quot;Symbol(&#39;x&#39;)_(1,)&quot; [&quot;color&quot;=&quot;black&quot;, &quot;label&quot;=&quot;x&quot;, &quot;shape&quot;=&quot;ellipse&quot;];</span>

<span class="go">#########</span>
<span class="go"># Edges #</span>
<span class="go">#########</span>

<span class="go">&quot;Add(Integer(2), Symbol(&#39;x&#39;))_()&quot; -&gt; &quot;Integer(2)_(0,)&quot;;</span>
<span class="go">&quot;Add(Integer(2), Symbol(&#39;x&#39;))_()&quot; -&gt; &quot;Symbol(&#39;x&#39;)_(1,)&quot;;</span>
<span class="go">}</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Printing</a><ul>
<li><a class="reference internal" href="#module-sympy.printing.printer">Printer Class</a><ul>
<li><a class="reference internal" href="#which-method-is-responsible-for-printing">Which Method is Responsible for Printing?</a></li>
<li><a class="reference internal" href="#example-of-custom-printer">Example of Custom Printer</a></li>
<li><a class="reference internal" href="#example-of-custom-printing-method">Example of Custom Printing Method</a><ul>
<li><a class="reference internal" href="#common-mistakes">Common mistakes</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#prettyprinter-class">PrettyPrinter Class</a></li>
<li><a class="reference internal" href="#module-sympy.printing.c">C code printers</a></li>
<li><a class="reference internal" href="#module-sympy.printing.cxx">C++ code printers</a></li>
<li><a class="reference internal" href="#module-sympy.printing.rcode">RCodePrinter</a></li>
<li><a class="reference internal" href="#fortran-printing">Fortran Printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.mathematica">Mathematica code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.maple">Maple code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.jscode">Javascript Code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.julia">Julia code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.octave">Octave (and Matlab) Code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.rust">Rust code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.aesaracode">Aesara Code printing</a></li>
<li><a class="reference internal" href="#module-sympy.printing.gtk">Gtk</a></li>
<li><a class="reference internal" href="#module-sympy.printing.lambdarepr">LambdaPrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.latex">LatexPrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.mathml">MathMLPrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.pycode">PythonCodePrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.python">PythonPrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.repr">srepr</a></li>
<li><a class="reference internal" href="#module-sympy.printing.str">StrPrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.tree">Tree Printing</a></li>
<li><a class="reference internal" href="#preview">Preview</a></li>
<li><a class="reference internal" href="#module-sympy.printing.conventions">Implementation - Helper Classes/Functions</a><ul>
<li><a class="reference internal" href="#module-sympy.printing.codeprinter">CodePrinter</a></li>
<li><a class="reference internal" href="#module-sympy.printing.precedence">Precedence</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-sympy.printing.pretty.pretty_symbology">Pretty-Printing Implementation Helpers</a></li>
<li><a class="reference internal" href="#dotprint">dotprint</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="polys/domainmatrix.html"
                        title="previous chapter">Introducing the domainmatrix of the poly module</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="rewriting.html"
                        title="next chapter">Term Rewriting</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/modules/printing.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="rewriting.html" title="Term Rewriting"
             >next</a> |</li>
        <li class="right" >
          <a href="polys/domainmatrix.html" title="Introducing the domainmatrix of the poly module"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >SymPy Modules Reference</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Printing</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/printing.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:25:39 GMT -->
</html>